jsTree-在Json数据中设置href属性 [英] jsTree - Setting href attributes in Json data
问题描述
我正在尝试创建一个'jsTree'树视图,该树视图从.Net Web服务获取数据. 除a节点的href属性外,其他所有东西都在工作.无论我尝试什么,它始终呈现为#". 据我从文档中了解到,任何数据对象中的所有属性都将复制到a节点.
Im trying to create a 'jsTree' treeview that gets it's data from a .Net webservice. Everything is working, except for the a-node's href attribute. Whatever I try, it always renders as '#'. As I understand from the documentation, all attributes in any data object get copied to the a-node.
下面是我当前的json对象的示例.无论如何,能否弄清楚为什么href属性没有复制到节点上?
Below is an example of my current json object. Can anyway figure out why the href attribute isn't copied to the nodes?
[ { "attributes" : { "id" : "rootnode_2",
"rel" : "root2"
},
"children" : [ { "attributes" : { "id" : "childnode_9",
"rel" : "folder"
},
"children" : [ { "attributes" : { "id" : "childnode_23",
"rel" : "folder"
},
"children" : null,
"data" : { "href" : "http://www.google.com",
"title" : "Test_Below_1"
},
"state" : null
} ],
"data" : { "href" : "http://www.google.com",
"title" : "Test_1"
},
"state" : null
},
{ "attributes" : { "id" : "childnode_10",
"rel" : "folder"
},
"children" : [ { "attributes" : { "id" : "childnode_24",
"rel" : "folder"
},
"children" : null,
"data" : { "href" : "http://www.google.com",
"title" : "Test_Below_2"
},
"state" : null
} ],
"data" : { "href" : "http://www.google.com",
"title" : "Test_2"
},
"state" : null
}
],
"data" : { "href" : "http://www.google.com",
"title" : "Glatt"
},
"state" : "closed"
} ]
这就是我初始化树的方式;
This is how I initialize the tree;
$("#jstreejson").jstree({
json_data : {
"data": treeObject
},
themes: {
"theme": "apple",
"dots": true,
"icons": true,
"url": "/Scripts/themes/apple/style.css"
},
plugins: ['core', 'themes', 'json', "json_data"]
});
推荐答案
所以...我不确定这是完全正确的.据我所知,您无法控制锚点属性,但是您可以执行的操作是将内容添加到json中的attr
哈希中,然后使用select_node.jstree
事件打开所需的链接,即:
So... I'm not sure that's entirely correct. You can't control the anchor attributes as far as I know, but what you can do add stuff to the attr
hash in the json and then use the select_node.jstree
event to open the desired link, i.e:
.bind("select_node.jstree", function (e,data) {
var href_address = data.rslt.obj.attr("whatever");
// open desired link
}
这篇关于jsTree-在Json数据中设置href属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!