Ank*_*kar 5 javascript jquery json jquery-plugins jstree
我想使用http://www.jstree.com/docs/json/ 上给出的“使用 JSON 填充树”中的 JSON 格式创建一个 jsTree(v 3.0.2)
// Expected format of the node (there are no required fields)
{
id : "string" // will be autogenerated if omitted
text : "string" // node text
icon : "string" // string for custom
state : {
opened : boolean // is the node open
disabled : boolean // is the node disabled
selected : boolean // is the node selected
},
children : [] // array of strings or objects
li_attr : {} // attributes for the generated LI node
a_attr : {} // attributes for the generated A node
}
Run Code Online (Sandbox Code Playgroud)
从实例中,我使用以下方法创建了我的树:
// create the instance
$('#jstree').jstree({
"core": {
"animation": 150,
"check_callback":true,
'data': new_data //json object
},
"types": {
"#": {
"valid_children": ["folder"]
},
"folder": {
"valid_children": ["file"]
},
"file": {
"valid_children": [""]
}
},
"plugins": ["dnd", "search", "wholerow", "types"]
});
Run Code Online (Sandbox Code Playgroud)
我想确保文件夹不会进入其他文件夹,文件也不会进入其他文件。文件只在文件夹中。
我想知道如何在我的 json 对象(new_data)中传递“类型”信息,以便应用类型。
我已经能够使该$("#jstree").jstree("set_type", $(this), "file");方法起作用,但我不喜欢脏检查方法。另外,我希望在JSON 中应用该类型,而不是在外部应用
另外,我不想使用这些方法在拖放时执行检查。我希望视觉提示(参见下面的屏幕截图)在可以/不可以将元素放在另一个地方时出现

对于jstree 3.x 版本:要回答有关如何在 JSON 对象中传递“类型”信息的问题的第一部分,您必须在与其他节点属性(如 id、text)相同的级别声明 type 属性。例如,节点的更新格式现在如下所示。请注意添加了 type 属性。
// Expected format of the node (there are no required fields)
{
id : "string" // will be autogenerated if omitted
text : "string" // node text
icon : "string" // string for custom
state : {
opened : boolean // is the node open
disabled : boolean // is the node disabled
selected : boolean // is the node selected
},
children : [] // array of strings or objects
li_attr : {} // attributes for the generated LI node
a_attr : {} // attributes for the generated A node
type : "string"
}
Run Code Online (Sandbox Code Playgroud)
示例节点 json 表示形式如下
{"id":"179356","text":"Node Name 1","state": {"opened":false,"disabled":false,"selected":false},"children":true,"li_attr": {"nodeType":"C","itemId":"12345"},"type":"file"}
Run Code Online (Sandbox Code Playgroud)
这个问题也在链接中讨论: https ://github.com/vakata/jstree/issues/473
| 归档时间: |
|
| 查看次数: |
1626 次 |
| 最近记录: |