我正在使用 jsTree,到目前为止它看起来不错。
我有一个节点列表,其 id 会随着每个新节点(g1,g2,g3 ...和其他一些节点,如 k1,k2,k3)而递增
我可以通过使用在文档加载时打开特定节点
"core": {
"animation": 0,
"open_parents": true,
"initially_open": ['g1']
},
但是我想打开所有以 'g' 而不是 'k' 开头的节点,可以使用 $(id^=g) 之类的东西吗?
更新:
节点是通过 web 服务动态创建的,例如
Dim oSB1 As StringBuilder = New StringBuilder
oSB1.Append(" <h5 >JSTree</h5> <div id='divtree' ><ul id='tree'> <li id='g1'><a href='#' class='usr'>1st Node</a><ul> <li><a href='#' rel='file'>1.1</a></li><li><a href='#' class='usr'>1.2</a></li><li><a href='#' class='file'>1.3</a></li></ul></li></ul><ul><li id='g2'><a href='#' class='usr'>2nd Node</a><ul> <li><a href='#' rel='file'>2.1</a></li><li><a href='#' >2.2</a></li></ul></ul> <ul><li id='k2'><a href='#' class='usr'>3rd Node</a><ul> <li><a href='#' rel='file'>3.1</a></li><li><a href='#' >3.2</a></li></ul></ul> <ul><li id='k2'><a href='#' class='usr'>4th Node</a><ul> <li><a href='#' rel='file'>4.1</a></li><li><a href='#' >4.2</a></li></ul></ul></div>")
Return oSB1.ToString
从 web 服务返回的数据分配给 jstree,因此我只需要打开 id 以“g”而不是“k”开头的节点,在上面的示例中只有 2 个节点,但想象一下是否有超过100个节点。
这棵树是这样称呼的
$("#G2").html(data.d);
$("#divtree").jstree(
{
"state": "open",
"animated": "slow",
"plugins": ["themes", "html_data", "ui", "crrm", "contextmenu"],
//working
"core": {
"animation": 0,
"open_parents": true,
"initially_open": ['g1']
},
"contextmenu": {
"items": function ($node) {
return {
"Create": {
"label": "Create a new Node",
"action": function (obj) {
$("#divtree").jstree("create_node", function () { alert("are you sure?") }, true);
this.create(obj);
}
},
"Rename": {
"label": "Rename Node",
"action": function (obj) {
$("#divtree").jstree("rename_node", function () { alert("you are trying to rename") }, true);
this.rename(obj);
}
},
"Delete": {
"label": "Delete Node",
"action": function (obj) {
$("#divtree").jstree("delete_node", function () { alert("Really!!?") }, true);
this.remove(obj);
}
}
};
}
}
});
她只有 id 为“g1”的节点打开,而我想打开所有以 id 为“g”开头的节点有没有办法让它运行?