【发布时间】:2012-03-12 19:45:07
【问题描述】:
使用 jsTree,我在尝试读取数据对象时得到 data.rslt undefined。
这是我的 jQuery,创建一棵树,加载 JSON,它应该在加载时将 data.rslt 对象输出到控制台。
$(function () {
$("#demo1").jstree({
"plugins" : [ "themes","json_data","ui", "crrm" ],
"json_data" : {
"ajax" : {
"url" : "categorytreejson.asp"
}
},
"ui" : {
"initially_select" : [ "root" ]
}
});
$("#demo1").bind("loaded.jstree", function (e, data) {
console.log(data.rslt)
});
});
这是 JSON 数据
{"data": "root", "attr": {"id": "root"}, "children": [{"data": "Photography", "attr": {"id": "Photography"}, "children": [{"data": "Lenses", "attr": {"id": "Lenses"}, "children": [{"data": "Telephoto", "attr": {"id": "Telephoto"}},{"data": "Macro", "attr": {"id": "Macro"}},{"data": "Other", "attr": {"id": "Other"}}]}]}]}
生成的 HTML
<li class="jstree-last jstree-open" id="root"><ins class="jstree-icon"> </ins><a class="" href="#"><ins class="jstree-icon"> </ins>root</a><ul style=""><li class="jstree-closed" id="Photography"><ins class="jstree-icon"> </ins><a class="" href="#"><ins class="jstree-icon"> </ins>Photography</a><ul><li class="jstree-last jstree-closed" id="Lenses"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Lenses</a><ul><li class="jstree-leaf" id="Telephoto"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Telephoto</a></li><li class="jstree-leaf" id="Macro"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Macro</a></li><li class="jstree-last jstree-leaf" id="Other"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Other</a></li></ul></li></ul></li></li></ul></li></ul></li>
还有 Firebug 中的数据对象。
args: []
inst: Object { data={...}, get_settings=function(), _get_settings=function(), more...}
rlbk: false
rslt: undefined
【问题讨论】: