问题描述
- ExtJS使用本地JSON建树,重复加载
- 初学Extjs,建树时使用了本地的JSON文件,但出现重复的问题,如图
json如下:
{success"": truedeps"": [ {id"": 1text"": ""Class 1""leaf"": falsechildren"": [ {id"": 2text"": ""Class 1.1""leaf"": truechildren"": [] } {id"": 3text"": ""Class 1.2""leaf"": truechildren"": [] } ] } {id"": 4text"": ""Class 2""leaf"": falsechildren"": [ {id"": 5text"": ""Class 2.1""leaf"": truechildren"": [] } ] } ]}
model如下:
Ext.define('App.model.Dep' { extend: 'Ext.data.Model' idProperty: 'depmodel' fields: [{ name: 'id' type: 'int' } { name: 'text' type: 'string' }]});
store:
Ext.define('App.store.DepTree' { extend: 'Ext.data.TreeStore' alias: 'store.deptree' model: 'App.model.Dep' autoLoad: false root: { id: 0 text: 'root' leaf: false expanded: true } proxy: { type: 'ajax' url: 'data/dep.json' reader: { type: 'json' rootProperty: 'deps' successProperty: 'success' } } listeners: { beforeload: function (store operation opts) { //阻止加载 if (!store._can_load_) { return false; } return true; } }});
treepanel:
Ext.define('App.view.dep.DepTree' { extend: 'Ext.tree.Panel' alias: 'widget.deptree' uses: [ 'App.store.DepTree' ] title: '部门' glyph: 0xf0c9 rootVisible: false lines: true viewModel: 'dep' listener: { beforeload: function () { } } initComponent: function () { var me = this; var store = Ext.create('App.store.DepTree'); me.store = store; me.callParent(); }});
解决方案
http://bbs.csdn.net/topics/390985332
时间: 2024-10-31 01:47:26