Ext Tree展开收缩时会异常的多生成一个子节点

minsheng0825 2015-10-15 05:23:46
页面加载时树菜单默认展开

这是拉到最底下的树菜单

点击根节点收缩时的情况

在子节点同样存在这样的问题
Ext.define('App.good.GoodCatalog', {
extend: 'Ext.tree.Panel',
alias: 'widget.goodCatalog',
title: '药材分类',
region: 'west',
id: 'goodCatalog',
width: 200,
split: true,
collapsible: true,
columns: [{
xtype: 'treecolumn',
text: '分类名称',
dataIndex: 'catalog_name',
width: '99%',
editor: {
xtype: 'textfield',
allowBlank: false
}
}],

// 初始化
initComponent: function () {
var me = this;
Ext.apply(this, {
store: Ext.create('Ext.data.TreeStore', {
model: 'GoodCatalogModel',
storeId: 'GoodCatalogStore',
autoLoad: false,
root: {
catalog_name: "中药材",
catalog_id: 1
}
}),
listeners: {
'boxready': this.boxOnReady,
'itemclick': this.menuClick,
'itemcollapse':this.collapseTree
}
});
this.callParent(arguments);
},

// 组件渲染完毕
boxOnReady: function () {
var me = this;
me.loadTreeOnce();
},

// 一次性加载树结构
loadTreeOnce: function () {
var me = this;
Ext.Ajax.request({
method: 'POST',
url: basePath + '/attribute/getCatalog.html',
params: {
'catalog_id': '1'
},
success: function(a) {
me.getRootNode().removeAll();
var nodes = Ext.decode(a.responseText);
if(nodes.result.length <= 0) return;
me.getRootNode().appendChild(nodes.result);
me.getRootNode().expand();
me.getRootNode().expandChildren(false);
},
error: function() {
error();
}
});
},
menuClick: function (the, record, item, index, e, eOpts) {
// 此处操控grid的新增
var grid = Ext.getCmp('goodAttributeGrid');
var addBtn = Ext.ComponentQuery.query('#addAttributeBtn', grid)[0],
delBtn = Ext.ComponentQuery.query('#delAttributeBtn', grid)[0],
addValBtn = Ext.ComponentQuery.query('#addAttributeValBtn', grid)[0]
if(record.raw.catalog_id.length == 10) {
addBtn.enable();
addValBtn.enable();
Ext.apply(grid.getStore().getProxy().extraParams, {
'catalogId': record.get('catalog_id')
});
grid.getStore().load();
} else {
addBtn.disable();
addValBtn.disable();
}
delBtn.disable();
},
collapseTree:function(record){
var me = this;
alert(record.get('catalog_name'));
me.getRootNode().reload();
}
});
Ext.define('GoodCatalogModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'catalog_id', mapping: 'catalog_id'},
{name: 'catalog_name', mapping: 'catalog_name'},
{name: 'del_flag', mapping: 'del_flag'},
{name: 'is_display', mapping: 'is_display'},
{name: 'is_light', mapping: 'is_light'},
{name: 'sort_id', mapping: 'sort_id'},
{name: 'father_id', mapping: 'father_id'}
]
});
这是我树菜单的代码
{"result":[{"id":"102","children":[{"id":"200","children":[{"id":"201","children":[],"isleaf":"1"
,"leaf":true,"catalog_id":"1006005001","catalog_name":"端午礼盒","father_id":"1006005","sort_id":null,"is_light"
:"1","is_display":null,"del_flag":"N","alias":null,"first_letter":null}],"isleaf":"0","leaf":false,"catalog_id"
:"1006005","catalog_name":"端午礼盒","father_id":"1006","sort_id":"5","is_light":"1","is_display":null,"del_flag"
:"N","alias":null,"first_letter":null}],"isleaf":"0","leaf":false,"catalog_id":"1006","catalog_name"
:"其他","father_id":"1","sort_id":"6","is_light":"1","is_display":null,"del_flag":"N","alias":null,"first_letter"
:null}]}

这是我的数据结构
请高手帮忙看看,谢谢了
...全文
87 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,888

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧