ExtJs动态生成treepanel的Json格式
在节点中加上"checked"属性,会自动生成checkbox。
获取选中节点
var nodeArray = "";
var nodesObj = mytree.getChecked();
var i;var length=nodesObj .length;
for (i = 0; i < length; i++) {
nodeArray += nodesObj[i].id + ','; //允许多选的情况。如果不允许多选,就直接nodesObj[i].id
}
nodeArray = nodeArray.substring(0, nodeArray.length - 1);
Json格式如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | [ { "text" : "To Do" , "cls" : "folder" , "expanded" : true , "children" :[ { "text" : "Go jogging" , "leaf" : true , "checked" : true }, { "text" : "Take a nap" , "leaf" : true , "checked" : false }, { "text" : "Climb Everest" , "leaf" : true , "checked" : false } ] }, { "text" : "Grocery List" , "cls" : "folder" , "children" :[ { "text" : "Bananas" , "leaf" : true , "checked" : false }, { "text" : "Milk" , "leaf" : true , "checked" : false }, { "text" : "Cereal" , "leaf" : true , "checked" : false }, { "text" : "Energy foods" , "cls" : "folder" , "children" :[ { "text" : "Coffee" , "leaf" : true , "checked" : false }, { "text" : "Red Bull" , "leaf" : true , "checked" : false } ] } ] }, { "text" : "Remodel Project" , "cls" : "folder" , "children" :[ { "text" : "Finish the budget" , "leaf" : true , "checked" : false }, { "text" : "Call contractors" , "leaf" : true , "checked" : false }, { "text" : "Choose design" , "leaf" : true , "checked" : false } ] } ] |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步