Jquery jstree问题
我正在使用XML作为我的JSTree树的数据源,但我找不到任何示例,您可以将XML中的节点设置为超链接,或者在任何地方使用自己的图标等设置自己的节点类型。有人这样做过吗?有没有示例?我想您正在寻找的。JSTree的文档说明: 在“项目”节点上设置的所有属性都将传输到生成的li节点。在“名称”节点上设置的所有属性都将传输到生成的节点 默认情况下,jsTree将当前页面的href地址添加到从XML标记(平面或嵌套)中的name节点生成的锚定标记中。您可以使用自己的地址覆盖href。下面是一个例子:Jquery jstree问题,jquery,jstree,Jquery,Jstree,我正在使用XML作为我的JSTree树的数据源,但我找不到任何示例,您可以将XML中的节点设置为超链接,或者在任何地方使用自己的图标等设置自己的节点类型。有人这样做过吗?有没有示例?我想您正在寻找的。JSTree的文档说明: 在“项目”节点上设置的所有属性都将传输到生成的li节点。在“名称”节点上设置的所有属性都将传输到生成的节点 默认情况下,jsTree将当前页面的href地址添加到从XML标记(平面或嵌套)中的name节点生成的锚定标记中。您可以使用自己的地址覆盖href。下面是一个例子:
<item id="link__1" parent_id="0">
<content>
<name title="Click here to go to website" href="http://google.com">Google</name>
</content>
</item>
有点晚,但希望这对您或其他偶然发现此答案的人有所帮助。jstree节点呈现为超链接(“a”或“锚定”标记),只要您设置正确。您可以将一些javascript绑定到节点选择事件,如下所示:
jQuery(".foldertree").bind("select_node.jstree", function (e, data) {
// use this to debug: alert("data.rslt.name=" + data.rslt.name + " data.rslt.obj.attr('rel')=" + data.rslt.obj.attr("rel"));
// to get selected node Id and type
var nodeId = data.rslt.obj.attr("id");
var nodeType = data.rslt.obj.attr("rel");
// to get node's immediate parent node
parentId = data.rslt.obj[0].parentNode.parentNode.id;
// use this info to call a method or go to another page
window.location = "somepage.aspx?" + nodeId;
}
下面是我如何用不同的图标设置不同的节点类型。我的树表示文件夹中的文档,因此我有“默认”(文件夹)和“表单”(文档)类型:
.. (各种设置内容)
. .
. (等)
. 它没有我想要的那种类型的例子。我想知道如何使我的一个xml节点成为超链接。@用户:这是什么意思?浏览器本身中的链接?是的,一个节点在单击时将重定向到另一个页面。@用户:我认为这不是jsTree的标准用例。你可能必须自己破解这个功能。奇怪……我认为使用这样的树来导航到不同的文档或网页将是它的主要用途之一。
jQuery(".foldertree").bind("select_node.jstree", function (e, data) {
// use this to debug: alert("data.rslt.name=" + data.rslt.name + " data.rslt.obj.attr('rel')=" + data.rslt.obj.attr("rel"));
// to get selected node Id and type
var nodeId = data.rslt.obj.attr("id");
var nodeType = data.rslt.obj.attr("rel");
// to get node's immediate parent node
parentId = data.rslt.obj[0].parentNode.parentNode.id;
// use this info to call a method or go to another page
window.location = "somepage.aspx?" + nodeId;
}
jQuery(".foldertree")
.jstree({
"types": {
// -2 means don't check (faster)
"max_depth": -2,
"max_children": -2,
// This will prevent moving or creating any other type as a root node
"valid_children": ["default"],
"types": {
// Folders
"default": {
// can have files and other folders inside of it
"valid_children": ["default", "form"],
"icon": {
"image": "css/jstree/folder.png"
}
},
// Documents (saved forms).
"form": {
// No children (so only leaf nodes)
"valid_children": "none",
// override theme icon
"icon": {
"image": "css/jstree/file.png"
}
},
} // end types (within types)
}, // end types (outer)
"themes":