1 <script type="text/javascript"> 2 Ext.require([ 3 'Ext.tree.*', 4 'Ext.data.*' 5 ]); 6 Ext.onReady(function() { 7 var store = Ext.create('Ext.data.TreeStore', { 8 model: 'Post', 9 proxy: { 10 type: 'ajax', 11 reader: 'json', 12 url: 'GetTree.ashx', 13 root: 'root' 14 }, 15 lazyFill: true 16 }); 17 18 Ext.create('Ext.tree.Panel', { 19 title: 'Simple Tree', 20 width: 500, 21 store: store, 22 autoScroll: true, 23 rootVisible: false, 24 enableDD: true, 25 26 renderTo: Ext.getBody() 27 }); 28 }); 29 </script>
上面的代码为加载树的代码,是ok的。
需求是这样的?需要把 GetTree.ashx返回的json数据存储到本地,存储为sessionStorage,存储,取出来都是没问题的。
现在需要把下面存储的json数据绑定到树(json里面的数据为后台处理的类型,是按照treeNode的属性生成的):
[{'id':'root','text':'所有数据','leaf':false,'checked':false,'expanded':true,'icon':null,'children':[{'id':'G_161','text':'东风','leaf':false,'checked':false,'expanded':false,'icon':null,'children':[{'id':'V_1082','text':'24000001510','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]},{'id':'V_1064','text':'24000001350','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]}]},{'id':'G_160','text':'临西','leaf':false,'checked':false,'expanded':false,'icon':null,'children':[{'id':'V_3274','text':'24000002013','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]},{'id':'V_2129','text':'24000003582','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]},{'id':'V_2128','text':'24000003644','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]},{'id':'V_2127','text':'24000003273','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]}]},{'id':'G_159','text':'高化','leaf':false,'checked':false,'expanded':false,'icon':null,'children':[{'id':'V_1968','text':'24000001588','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]},{'id':'V_645','text':'24000001799','leaf':true,'checked':false,'expanded':false,'icon':'Images/car/car2_blue.png','children':[]}]}]}]
用jsonReader,ArrayReader,都没有成功。
正在学习Ext的api。
感谢。