1.第一步
//加载store
var store = Ext.create('Ext.data.TreeStore', {proxy: {
type: 'ajax',
url: path('/omsAddressTest/listTree.json'),
reader: {
type: 'json',
root: 'result'
}
},
fields:['id','text','level']
});
2.第二步
var toolbarPanel = new Ext.panel.Panel({
dockedItems: [{
xtype: 'toolbar',
items: [{
xtype : 'button',
id : 'btnAdd',
height : 24,
text : '添加地区',
iconCls : 'icon-edit',
handler : addAddress
}, {
xtype : 'button',
id : 'btnEdit',
disabled : true,
height : 24,
text : '查看地区',
iconCls : 'icon-edit',
handler : editAddress
},'->', {
xtype : 'button',
id : 'btnOrder',
disabled : true,
height : 24,
text : '排序',
iconCls : 'icon-edit',
handler : function(){
}
}]
}]
});
3.第三步
var tree = Ext.create("Ext.tree.Panel",{
id:'addressTree',
dockedItems: [toolbarPanel],
selModel: Ext.create('Ext.selection.CheckboxModel', {
checkOnly: false
}),
width:300,
height:500,
singleExpand: true,
rootVisible: false, //默认不显示根节点
root: {
id:'root',
leve:0,
text: ''
},
store:store
});
tree.getSelectionModel().on('selectionchange',function(thiz, selections) {
Ext.getCmp('btnEdit').setDisabled(!(selections.length == 1));
if(selections.length == 1){
editAddressSysId = selections[0].internalId; //得到选中的主键ID
}
});