问候,我正在使用jsTree来生成我的分层数据.JsTree生成如下:
$(function() {
$("#industries").tree({
data: {
type: "json",
opts: {
url: "/Admin/GetIndustries/"
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
它的工作原理和jsonresult是这样的:
[{"attributes":[],"data":{"title":"Adwokaci, Notariusze","id":"1a051101-c3fa-48f2-b2e1-c60d1b67ea22"},"children":[{"attributes":[],"data":{"title":"Kancelarie adwokackie","id":"26d6cff1-3c7f-4a2f-bf5a-422e08127b43"
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何在某些隐藏字段中保存所选节点的ID?我做这样的事情:
<script type="text/javascript">
$("#industries").click(function() {
var tree = $.tree.reference("industries");
var t = $.tree.focused(); if (t.selected) t.selected; else alert("Select a node first");
alert(t.id);
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我进入警报窗口"未定义".有人可以帮帮我吗?
编辑: 我已经更改了jstree实例,如下所示:
$(function() {
$("#industries").tree({
callback: {
onselect: function(NODE, TREE_OBJ) {
alert(NODE.id);
}
},
data: {
type: "json",
opts: {
url: "/Admin/GetIndustries/"
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
我得到空洞的警觉