extjs4 tree 叶子节点要id唯一今天遇到一个问题,从后台传输数据到前台,显示的是tree,tree有根和子叶组成,
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的值改为不同,就能正常显示了