87,977
社区成员
发帖
与我相关
我的任务
分享
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}]}