extjs4 tree 叶子节点要id唯一

今天遇到一个问题,从后台传输数据到前台,

显示的是tree,tree有根和子叶组成,就是显示不出来。
我的亲爹,找来找去还是测试出来了。
先说答案: 一颗树,应该保证该树的root,叶子的id是唯一的。

 



问题所在:
我用的mysql自增的方式,所有主键上 1,2 3 4 5 
而我的根节点比如图中的开发部65 与 叶子节点比如图中的子1节点是
两个对象,他们都是用mysql自增的方式,因此错误导致根节点的id和
叶子节点的id有可能重复。

测试数据(正常显示)
{
children : [{
text : '开发部',
id : 'absolute22',
leaf : false,
children : [{
text : '移动开发部',
id : 'absolute221',
leaf : true
                            
}, {
text : '前段开发部',
id : 'pswdupdate222',
leaf : true
}]

}, {
text : '设计部',
id : 'absolute32',
leaf : false,
children : [{
text : '移动设计部',
id : 'absolute321',
leaf : true

}, {
text : '前段设计部',
id : 'pswdupdate322',
leaf : true
}]

}]
}

实际后台数据(略有改动):(无法正常显示)
{
id : '-1',
children : [{
text : '开发部3',
id : '1',
children : [{
text : '子1',
id : '1',
//children : [],
leaf : true
}, {
text : '方法',
id : '2',
//children : [],
leaf : true
}, {
text : '方法',
id : '3',
//children : [],
leaf : true
}, {
text : 'new1',
id : 4,
//children : [],
leaf : true
}, {
text : 'dd',
id : '5',
//children : [],
leaf : true
}, {
text : 'ff',
id : '7',
//children : [],
leaf : true
}, {
text : '这个小组',
id : '8',
children : [],
leaf : true
}],
leaf : false
}, {
text : '人力资源部2',
id : '2',
children : [{
text : 'ff',
id : '6',
//children : [],
leaf : true
}, {
text : '总经理秘书',
    id : '10',
//children : [],
leaf : true
}],
leaf : false
}]
//"leaf" : false
}

把id的值改为不同,就能正常显示了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值