我正在尝试创建一个“jsTree” TreeView ,它从 .Net Web 服务获取数据。 除了 a 节点的 href 属性之外,一切正常。无论我尝试什么,它总是呈现为“#”。 据我从文档中了解到,任何数据对象中的所有属性都会复制到 a 节点。
下面是我当前的 json 对象的示例。无论如何可以弄清楚为什么 href 属性没有复制到节点吗?
[ { "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"
} ]
这就是我初始化树的方式;
$("#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"]
});
最佳答案
所以...我不确定这是否完全正确。据我所知,您无法控制 anchor 属性,但您可以将内容添加到 json 中的 attr
哈希中,然后使用 select_node.jstree
事件打开所需的链接,即:
.bind("select_node.jstree", function (e,data) {
var href_address = data.rslt.obj.attr("whatever");
// open desired link
}
关于json - jsTree - 在 Json 数据中设置 href 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9513301/