こんにちは、jsTree を使用して階層データを生成しています。JsTree は次のように生成されます。
$(function() {
$("#industries").tree({
data: {
type: "json",
opts: {
url: "/Admin/GetIndustries/"
}
}
});
});
動作し、jsonresult は次のようになります。
[{"attributes":[],"data":{"title":"Adwokaci, Notariusze","id":"1a051101-c3fa-48f2-b2e1-c60d1b67ea22"},"children":[{"attributes":[],"data":{"title":"Kancelarie adwokackie","id":"26d6cff1-3c7f-4a2f-bf5a-422e08127b43"
私の質問は: 選択したノードの 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);
});
しかし、それは機能しません。警告ウィンドウに「未定義」が表示されます。誰か助けてくれませんか?
編集: jstree インスタンスを次のように変更しました。
$(function() {
$("#industries").tree({
callback: {
onselect: function(NODE, TREE_OBJ) {
alert(NODE.id);
}
},
data: {
type: "json",
opts: {
url: "/Admin/GetIndustries/"
}
}
});
});
そして私は空のアラートを受け取ります