我有jsTree從JSON頁面加載數據並正確顯示。我試圖選擇默認的根節點,但我無法讓它工作。無法獲取jQuery插件jsTree最初選擇一個節點
這裏是我的jQuery:
$(function() {
$("#demo1").jstree({
"plugins" : [ "themes","json_data","ui" ],
"json_data" : {
"ajax" : {
"url" : "categorytreejson.asp"
},
"ui" : {
"initially_select" : [ "root" ]
},
}
});
});
這裏是categorytreejson.asp我的JSON這驗證使用JSONLint:
{
"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>
並通過螢火蟲觀察所得到的數據對象:
args: []
inst: Object { data={...}, get_settings=function(), _get_settings=function(), more...}
rlbk: false
rslt: undefined
我假設大多數的問題是,因爲結果是空的,但我不知道爲什麼?
你說得對。我很高興我有另一雙眼睛。 非常感謝。 我仍然無法弄清楚爲什麼我沒有rslt對象。 – Chris 2012-03-12 19:13:18