extjs4.0 动态异步加载节点数据

直接上代码!

样例1:传统的树形

var store2 = Ext.create('Ext.data.TreeStore', {
        proxy: {
            type: 'ajax',
            url: 'WebForm1.aspx'
        },
        fields:['id','text']//跟旧版本extjs一样,节点的id和显示文本
    });
	
var AsyncTree2 = Ext.create("Ext.tree.Panel",{
		title: 'Simple Tree2',
		width:300,
		height:500,
		collapsible: true,
		singleExpand: true,
    	root: {
	    	id:1,
	        text: "Root node",
	        expanded: true
        
    	},
    store:store2,
    renderTo:  Ext.getBody()
});

样例2:TreeGrid

var store = Ext.create('Ext.data.TreeStore', {
        proxy: {
            type: 'ajax',
            url: 'WebForm1.aspx'
        },
        fields:['projectId','project','taskId','id','text']
    });
    
	var AsyncTree = Ext.create("Ext.tree.Panel",{
		title: 'Simple Tree',
		width:300,
		height:500,
		collapsible: true,
		useArrows: true,
		multiSelect: true,
		//singleExpand: true,
    	root: {
	    	id:1,
	        text: "Root node",
	        expanded: true
        
    	},
    columns:[
    	{ xtype: 'treecolumn', text:'text',dataIndex:'taskId'},//要标明为treecolumn,否则显示不出节点前面的小图标
    	
    	{text:'ParentId',dataIndex:'projectId'}//第二列
    ],
    store:store,
    renderTo: Ext.getBody()

	});


当首次点击子节点时,会Post一个参数node(节点的id值)到后台服务器,用Firebug可以临看到。


WebForm1.aspx返回的JSON样例(根据实际应用组织)

[{projectId: 100, text: 'G112', taskId: 112,  estimate: 6, rate: 150, due:'06/24/2007',checked:true},
	    {projectId: 100, text: 'A113', id: 113,  estimate: 4, rate: 150, due:'06/25/2007',leaf:true},
	    {projectId: 100, text: 'V114', id: 114,  estimate: 4, rate: 150, due:'06/27/2007'},
	    {projectId: 100, text: 'C115', id: 115,  rate: 0, due:'06/29/2007'}]


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dafeng168

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值