AsyncTreeNode 出问题了!请大家看看

zhangby 2008-06-20
我写了一个菜单,已经获得了json的数据,但是怎么一点+,就什么都没有了,请问高手们给点提示!刚学习。

json数据如下:

[{"text":"Templates","id":"\/Templates","cls":"folder"},{"text":"real","id":"\/real","cls":"folder"}

,{"text":"Desktop","id":"\/Desktop","cls":"folder"},{"text":"usedoc","id":"\/usedoc","cls":"folder"}

,{"text":"tmp.php","id":"\/tmp.php","leaf":true,"cls":"file"},{"text":"downloads","id":"\/downloads"

,"cls":"folder"},{"text":"workspace","id":"\/workspace","cls":"folder"},{"text":"tmp","id":"\/tmp","cls"

:"folder"},{"text":"Projects","id":"\/Projects","cls":"folder"},{"text":"study","id":"\/study","cls"

:"folder"},{"text":"zhangby_doc","id":"\/zhangby_doc","cls":"folder"},{"text":"thinkphp1.0.2.pdf","id"

:"\/thinkphp1.0.2.pdf","leaf":true,"cls":"file"},{"text":"sqldeveloper","id":"\/sqldeveloper","cls":"folder"

},{"text":"reload_all_tabs.png","id":"\/reload_all_tabs.png","leaf":true,"cls":"file"},{"text":"pw","id"

:"\/pw","leaf":true,"cls":"file"},{"text":"Zend","id":"\/Zend","cls":"folder"},{"text":"\u63a1\u8cfc

\u90e8\u5206\u5de5\u8868.xls","id":"\/\u63a1\u8cfc\u90e8\u5206\u5de5\u8868.xls","leaf":true,"cls":"file"

},{"text":"tmp.php~","id":"\/tmp.php~","leaf":true,"cls":"file"},{"text":"hkparameter.txt~","id":"\/hkparameter

.txt~","leaf":true,"cls":"file"},{"text":"Test.txt~","id":"\/Test.txt~","leaf":true,"cls":"file"},{"text"

:"EIOffice","id":"\/EIOffice","cls":"folder"},{"text":"share","id":"\/share","cls":"folder"},{"text"

:"attd_over.php~","id":"\/attd_over.php~","leaf":true,"cls":"file"},{"text":"ixwebhosting.txt~","id"

:"\/ixwebhosting.txt~","leaf":true,"cls":"file"},{"text":"Smarty-2.6.14-docs.pdf","id":"\/Smarty-2.6

.14-docs.pdf","leaf":true,"cls":"file"},{"text":"sal_count.sql","id":"\/sal_count.sql","leaf":true,"cls"

:"file"},{"text":"Test-Sql.sql~","id":"\/Test-Sql.sql~","leaf":true,"cls":"file"},{"text":"\u516c\u5171

\u7684","id":"\/\u516c\u5171\u7684","cls":"folder"},{"text":"\u6587\u6863","id":"\/\u6587\u6863","cls"

:"folder"},{"text":"\u97f3\u4e50","id":"\/\u97f3\u4e50","cls":"folder"},{"text":"\u56fe\u7247","id":"

\/\u56fe\u7247","cls":"folder"},{"text":"\u89c6\u9891","id":"\/\u89c6\u9891","cls":"folder"},{"text"

:"test.sql","id":"\/test.sql","leaf":true,"cls":"file"},{"text":"chaoju.zl","id":"\/chaoju.zl","leaf"

:true,"cls":"file"},{"text":"stardict.tar.gz","id":"\/stardict.tar.gz","leaf":true,"cls":"file"},{"text"

:"license_key","id":"\/license_key","cls":"folder"},{"text":"sal_count.sql~","id":"\/sal_count.sql~"

,"leaf":true,"cls":"file"},{"text":"test.sql~","id":"\/test.sql~","leaf":true,"cls":"file"},{"text":"HRCS

.pdf","id":"\/HRCS.pdf","leaf":true,"cls":"file"},{"text":"TestSql.sql~","id":"\/TestSql.sql~","leaf"

:true,"cls":"file"},{"text":"EIOfficelog.txt","id":"\/EIOfficelog.txt","leaf":true,"cls":"file"},{"text"

:"abc.sql","id":"\/abc.sql","leaf":true,"cls":"file"},{"text":"shell","id":"\/shell","cls":"folder"}

,{"text":"addressbook.tar.gz","id":"\/addressbook.tar.gz","leaf":true,"cls":"file"},{"text":"ext.pdf"

,"id":"\/ext.pdf","leaf":true,"cls":"file"},{"text":"\u4e1c\u7bad\u9700\u6c42.pdf","id":"\/\u4e1c\u7bad

\u9700\u6c42.pdf","leaf":true,"cls":"file"},{"text":"ab.txt~","id":"\/ab.txt~","leaf":true,"cls":"file"

},{"text":"abc.sql~","id":"\/abc.sql~","leaf":true,"cls":"file"},{"text":"autosendmail.sh~","id":"\/autosendmail

.sh~","leaf":true,"cls":"file"},{"text":"addressmail.vcf","id":"\/addressmail.vcf","leaf":true,"cls"

:"file"},{"text":"this_tax.sql","id":"\/this_tax.sql","leaf":true,"cls":"file"},{"text":"\u9700\u6c42

.eio","id":"\/\u9700\u6c42.eio","leaf":true,"cls":"file"},{"text":"\u9700\u6c421.pdf","id":"\/\u9700

\u6c421.pdf","leaf":true,"cls":"file"},{"text":"\u9700\u6c421.xls","id":"\/\u9700\u6c421.xls","leaf"

:true,"cls":"file"},{"text":"2F\u8bf4\u660e\u4e66.pdf","id":"\/2F\u8bf4\u660e\u4e66.pdf","leaf":true

,"cls":"file"},{"text":"this_tax.sql~","id":"\/this_tax.sql~","leaf":true,"cls":"file"},{"text":"\u901a

\u5b89\u53cc\u7ede\u89c6\u9891\u5361\u4e3b\u677f.eio","id":"\/\u901a\u5b89\u53cc\u7ede\u89c6\u9891\u5361

\u4e3b\u677f.eio","leaf":true,"cls":"file"},{"text":"dwhelper","id":"\/dwhelper","cls":"folder"},{"text"

:"salary_count.sql","id":"\/salary_count.sql","leaf":true,"cls":"file"},{"text":"Ttest_sql.sql","id"

:"\/Ttest_sql.sql","leaf":true,"cls":"file"},{"text":"salary_count.sql~","id":"\/salary_count.sql~","leaf"

:true,"cls":"file"},{"text":"se_value.php","id":"\/se_value.php","leaf":true,"cls":"file"},{"text":"Ttest_sql

.sql~","id":"\/Ttest_sql.sql~","leaf":true,"cls":"file"},{"text":"per_personnal_20080424.php","id":"

\/per_personnal_20080424.php","leaf":true,"cls":"file"},{"text":"\u7814\u767c\u53ca\u6280\u8853\u4eba

\u54e1\u7e3e\u6548\u8003\u6838\u8207\u6fc0\u52f5\u7cfb\u7d71.eio","id":"\/\u7814\u767c\u53ca\u6280\u8853

\u4eba\u54e1\u7e3e\u6548\u8003\u6838\u8207\u6fc0\u52f5\u7cfb\u7d71.eio","leaf":true,"cls":"file"},{"text"

:"abc.php","id":"\/abc.php","leaf":true,"cls":"file"},{"text":"20080428_sql.txt","id":"\/20080428_sql

.txt","leaf":true,"cls":"file"},{"text":"abc.php~","id":"\/abc.php~","leaf":true,"cls":"file"},{"text"

:"per_personnal_20080426.php","id":"\/per_personnal_20080426.php","leaf":true,"cls":"file"},{"text":"ps_report

.php","id":"\/ps_report.php","leaf":true,"cls":"file"},{"text":"20080428_sql.txt~","id":"\/20080428_sql

.txt~","leaf":true,"cls":"file"},{"text":"test1.txt~","id":"\/test1.txt~","leaf":true,"cls":"file"},

{"text":"ps_report_20080502.php","id":"\/ps_report_20080502.php","leaf":true,"cls":"file"},{"text":"a

.php","id":"\/a.php","leaf":true,"cls":"file"},{"text":"zsalary.inc.php","id":"\/zsalary.inc.php","leaf"

:true,"cls":"file"},{"text":"a.php~","id":"\/a.php~","leaf":true,"cls":"file"},{"text":"ps_report_20080503

.php","id":"\/ps_report_20080503.php","leaf":true,"cls":"file"},{"text":"attd.inc.php","id":"\/attd.inc

.php","leaf":true,"cls":"file"},{"text":"Skype_back_data","id":"\/Skype_back_data","cls":"folder"},{"text"

:"attd.inc_20080505.php","id":"\/attd.inc_20080505.php","leaf":true,"cls":"file"},{"text":"attd.inc_20080505_new

.php","id":"\/attd.inc_20080505_new.php","leaf":true,"cls":"file"},{"text":"zpublic.class.php","id":"

\/zpublic.class.php","leaf":true,"cls":"file"},{"text":"per_personnal.txt","id":"\/per_personnal.txt"

,"leaf":true,"cls":"file"},{"text":"per_personnal.eio","id":"\/per_personnal.eio","leaf":true,"cls":"file"

},{"text":"attd_over.php","id":"\/attd_over.php","leaf":true,"cls":"file"},{"text":"\u8f9e\u5de5\u4e66

.eio","id":"\/\u8f9e\u5de5\u4e66.eio","leaf":true,"cls":"file"},{"text":"\u672a\u547d\u540d.jpg","id"

:"\/\u672a\u547d\u540d.jpg","leaf":true,"cls":"file"},{"text":"human_scode.tar.gz","id":"\/human_scode

.tar.gz","leaf":true,"cls":"file"},{"text":"ext\u5b66\u4e60\u6587\u6863.odt","id":"\/ext\u5b66\u4e60

\u6587\u6863.odt","leaf":true,"cls":"file"},{"text":"20080327239.jpg","id":"\/20080327239.jpg","leaf"

:true,"cls":"file"},{"text":"ext\u5b66\u4e60\u6587\u6863.doc","id":"\/ext\u5b66\u4e60\u6587\u6863.doc"

,"leaf":true,"cls":"file"},{"text":"yuexing.xcf","id":"\/yuexing.xcf","leaf":true,"cls":"file"},{"text"

:"20077221442624300.gif","id":"\/20077221442624300.gif","leaf":true,"cls":"file"},{"text":"images.jpg"

,"id":"\/images.jpg","leaf":true,"cls":"file"},{"text":"aaa.gif","id":"\/aaa.gif","leaf":true,"cls":"file"

},{"text":"thumb.jpg","id":"\/thumb.jpg","leaf":true,"cls":"file"},{"text":"generator.yml","id":"\/generator

.yml","leaf":true,"cls":"file"},{"text":"sfExtjs2Helper.php","id":"\/sfExtjs2Helper.php","leaf":true

,"cls":"file"},{"text":"Yzdwch6.ttf","id":"\/Yzdwch6.ttf","leaf":true,"cls":"file"},{"text":"yzdwfs6

.ttf","id":"\/yzdwfs6.ttf","leaf":true,"cls":"file"},{"text":"yzdwhj6.ttf","id":"\/yzdwhj6.ttf","leaf"

:true,"cls":"file"},{"text":"yzdwkj6.ttf","id":"\/yzdwkj6.ttf","leaf":true,"cls":"file"}]


代码如下:

StructureMenuPanel = function() {
StructureMenuPanel.superclass.constructor.call(this, {
autoScroll : true,
animate : true,
border : false,
rootVisible : false,
root : new Ext.tree.TreeNode( {
text : '组织结构',
draggable : false,
expanded : true
})
});
this.fileNode=new Ext.tree.AsyncTreeNode( {
text : "FileList",
draggable:false, // disable root node dragging
id:"source",
loader:new Ext.tree.TreeLoader({url:"get-nodes.php"}),
});
    this.on('click', function(node) {
        Ext.MessageBox.alert('Status', node+'Changes saved successfully.');
    });
this.root.appendChild(this.fileNode);
    this.root.expand(false, /*no anim*/ false);
}
Ext.extend(StructureMenuPanel, Ext.tree.TreePanel);
equalto 2008-06-24
看着就晕啊.
首先,要确定个事情,你的tree是否是一次加载的,
如果是,则不需要async,直接的loop json数据,将其一个个对应生成TreeNode,并且appendChild;
如果不是,那就只生成一个根节点就可以了,但是你的url答复数据,需要考虑参数.
cheng022074 2008-06-29
好象没有这样复杂吧,建议参与EXTJS的docs项目中的API的那个Tree,那个Tree就是一次必从本地载入的
Global site tag (gtag.js) - Google Analytics