jsTree不创建特定类型的节点
我遵循了 http://www.jstree.com/demo/types 的最后一个示例中的代码片段 创建给定类型的节点,但我不知道为什么它不起作用。
HTML 片段:
<form>
<button id="buttonAddMenu" type="button">Créer Menu</button>
<button id="buttonAddParameter" type="button">Créer Paramètre</button>
<button id="buttonRename" type="button">Renomer</button>
<button id="buttonRemove" type="button">Supprimer</button>
<button id="buttonShowData" type="button">Show Data</button>
</form>
<div id="checkListParams">
<ul>
<li id="new001"><a href="#">Root menu 1</a></li>
<li id="new002"><a href="#">Root menu 2</a>
<ul>
<li><a href="#">Menu 2.1</a></li>
<li><a href="#">Menu 2.2</a>
<ul>
<li rel="parameter"><a href="#">Parameter A</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Javascript:
$(document).ready(function() {
//================
//Configuring tree
//================
$("#checkListParams").jstree({
"ui" : {
"select_limit": 1
},
"contextmenu" : {
"select_node": true
},
"hotkeys" : {
"del": false //disable deleting nodes only via DEL key
},
"types" : {
"valid_children" : [ "default" ],
"use_data" : true,
"types" : {
"default" : {
"valid_children" : [ "all" ]
},
"parameter" : {
"icon" : {
"image" : "site/media/img/icons/checklist_parameter.png"
},
"valid_children" : [ "none" ],
"create_node": false
}
}
},
"core" : { "initially_open" : [ "all" ] },
"plugins" : [
"themes", "html_data", "xml_data", "ui", "crrm", "dnd",
"contextmenu", "hotkeys", "types"
]
});
//==========================
//Configuring button actions
//==========================
$("#buttonAddMenu").click(function() {
$("#checkListParams").jstree("create");
});
$("#buttonAddParameter").click(function() {
//$("#checkListParams").jstree("create", null, "inside"); //works!
$("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } });
});
$("#buttonRemove").click(function() {
$("#checkListParams").jstree("remove");
})
$("#buttonRename").click(function() {
$("#checkListParams").jstree("rename");
})
$("#buttonShowData").click(function() {
var nodes = $("#checkListParams").jstree("get_xml", {
"li_attr" : [ "id" , "class", "rel" ]
});
alert(nodes);
})
});
行
$("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } });
不工作。我尝试将类型更改为“默认”,但没有成功...另外,我没有收到错误消息(我不喜欢在事情不运行时没有收到错误消息)。
先感谢您。
更新
使用http://osdir.com中的说明解决/ml/jstree/2011-04/msg00126.html 。 明确列出所有有效的子项(而不是使用“全部”)解决了问题。
明天我会检查 jsTree 问题页面中是否有类似的 bug,也许会添加一个新的 bug。
不管怎样,谢谢。
I've followed the code fragment in the last example of http://www.jstree.com/demo/types to create a node of a given type and I've got no idea why it doesn't work.
HTML Fragment:
<form>
<button id="buttonAddMenu" type="button">Créer Menu</button>
<button id="buttonAddParameter" type="button">Créer Paramètre</button>
<button id="buttonRename" type="button">Renomer</button>
<button id="buttonRemove" type="button">Supprimer</button>
<button id="buttonShowData" type="button">Show Data</button>
</form>
<div id="checkListParams">
<ul>
<li id="new001"><a href="#">Root menu 1</a></li>
<li id="new002"><a href="#">Root menu 2</a>
<ul>
<li><a href="#">Menu 2.1</a></li>
<li><a href="#">Menu 2.2</a>
<ul>
<li rel="parameter"><a href="#">Parameter A</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Javascript:
$(document).ready(function() {
//================
//Configuring tree
//================
$("#checkListParams").jstree({
"ui" : {
"select_limit": 1
},
"contextmenu" : {
"select_node": true
},
"hotkeys" : {
"del": false //disable deleting nodes only via DEL key
},
"types" : {
"valid_children" : [ "default" ],
"use_data" : true,
"types" : {
"default" : {
"valid_children" : [ "all" ]
},
"parameter" : {
"icon" : {
"image" : "site/media/img/icons/checklist_parameter.png"
},
"valid_children" : [ "none" ],
"create_node": false
}
}
},
"core" : { "initially_open" : [ "all" ] },
"plugins" : [
"themes", "html_data", "xml_data", "ui", "crrm", "dnd",
"contextmenu", "hotkeys", "types"
]
});
//==========================
//Configuring button actions
//==========================
$("#buttonAddMenu").click(function() {
$("#checkListParams").jstree("create");
});
$("#buttonAddParameter").click(function() {
//$("#checkListParams").jstree("create", null, "inside"); //works!
$("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } });
});
$("#buttonRemove").click(function() {
$("#checkListParams").jstree("remove");
})
$("#buttonRename").click(function() {
$("#checkListParams").jstree("rename");
})
$("#buttonShowData").click(function() {
var nodes = $("#checkListParams").jstree("get_xml", {
"li_attr" : [ "id" , "class", "rel" ]
});
alert(nodes);
})
});
The line
$("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } });
is not working. I've tried to change the type to "default", without success... Also, I've got no error messages (I don't like not getting error messages when things don't run).
Thank you in advance.
UPDATE
Solved using instructions in http://osdir.com/ml/jstree/2011-04/msg00126.html .
Explicitly listing all valid children (instead of using "all") solved the problem.
I'll check whether a similar bug is filed in jsTree issues pages tomorrow, maybe adding a new one.
Thanks anyway.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是按照某些人的要求重复上述更新:
使用 http:// 中的说明解决了osdir.com/ml/jstree/2011-04/msg00126.html 。明确列出所有有效的子项(而不是使用“全部”)解决了问题。
明天我会检查 jsTree 问题页面中是否有类似的 bug,也许会添加一个新的 bug。
不管怎样,谢谢。
Just repeating the above UPDATE as asked by some people:
Solved using instructions in http://osdir.com/ml/jstree/2011-04/msg00126.html . Explicitly listing all valid children (instead of using "all") solved the problem.
I'll check whether a similar bug is filed in jsTree issues pages tomorrow, maybe adding a new one.
Thanks anyway.