日期:2014-05-16  浏览次数:20398 次

EXTJS的treepanel组件使用问题
treepanel组件如何实现如gridpanel中的jsonstore功能?tree组件需要的JSON格式为[{},{}],现在我想让它像grid加jsonstore使用一样定义格式为:{success:true,data:[{},{}]},请问大家如何实现?我用的版本是3.4

------解决方案--------------------
如果你是想用success的布尔值在tree组件里写逻辑,你可以先将数据从FWQ请求回前台,封装成js object,然后让tree接收封装好的静态数据.

Ext.onReady(function(){
var jsonData ={success:true,data: [{                
text: 'Menu Option 1',
leaf: true            
},{                
text: 'Menu Option 2',
leaf: true            
},{                
text: 'Menu Option 3',
leaf: true            
}]
}
new Ext.Viewport({    
layout: 'border',    
items: [{        
region: 'center',       
title: 'Navigation',
xtype: 'treepanel',        
width: 200,            
loader: new Ext.tree.TreeLoader(),
root: new Ext.tree.AsyncTreeNode({            
expanded: true,
children: jsonData.data
}),        
rootVisible: false,
listeners: {            
click: function(n) {
                Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"'+'\n'+'success:'+'\t'+jsonData.success);
}
}
}]
});
})