yansenlei/VJsoneditor

如何访问对应vue component对象

Closed this issue · 8 comments

zlwen commented
如何访问对应vue component对象

具体实现的component吗?

zlwen commented

我想根据条件设置jsoneditor 是否可以编辑,动态改变options.onEditable方法不管用,有什么方法吗

options: {
    mode: 'view'
}

设置只读模式可以吗?

zlwen commented

var options = {
mode: "code",
mainMenuBar: false,
statusBar: true,
search: true,
onEditable: function(node) {
return false; // 我这里需要动态改 但好像没生效
}
};

@zlwen

我尝试了下,return false是可以生效的

https://codesandbox.io/embed/vigorous-goldwasser-21yjz37j2y

zlwen commented

... 你没理解我的意思 我的意思是这里的返回值需要动态改 在某些条件下可以编辑 某些条件不能编辑

@zlwen

The function must either return a boolean value to set both the nodes field and value editable or read-only, or return an object {field: boolean, value: boolean} to set set the read-only attribute for field and value individually.

In modes text and code, the callback is invoked as editable(node) where node is an empty object (no field, value, or path). In that case the function can return false to make the text or code editor completely read-only.

文档中提示textcode模式中的回调参数是空对象,我用tree模式可以设置条件限制编辑。这样可以满足你的需求吗?

options: {
  mode: "tree",
  onEditable: function(node) {
    if (node.field === 'Number') {
      return {field: false, value: false};
    }
    return {field: true, value: true};
  }
}