首页 > 语言 > JavaScript > 正文

ExtJs动态生成treepanel的Json格式

2024-05-06 16:23:27
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要介绍了ExtJs动态生成treepanel的Json格式的相关资料,需要的朋友可以参考下

在节点中加上"checked"属性,会自动生成checkbox。

获取选中节点

 

 
  1. var nodeArray = ""; 
  2. var nodesObj = mytree.getChecked(); 
  3.  
  4. var i;var length=nodesObj .length; 
  5. for (i = 0; i < length; i++) { 
  6. nodeArray += nodesObj[i].id + ','; //允许多选的情况。如果不允许多选,就直接nodesObj[i].id  
  7. } 
  8.  
  9. nodeArray = nodeArray.substring(0, nodeArray.length - 1);  

Json格式如下:

 

 
  1. [{ 
  2. "text": "To Do",  
  3. "cls": "folder", 
  4. "expanded": true, 
  5. "children": [{ 
  6. "text": "Go jogging", 
  7. "leaf": true, 
  8. "checked": true 
  9. },{ 
  10. "text": "Take a nap", 
  11. "leaf": true, 
  12. "checked": false 
  13. },{ 
  14. "text": "Climb Everest", 
  15. "leaf": true, 
  16. "checked": false 
  17. }] 
  18. },{ 
  19. "text": "Grocery List", 
  20. "cls": "folder", 
  21. "children": [{ 
  22. "text": "Bananas", 
  23. "leaf": true, 
  24. "checked": false 
  25. },{ 
  26. "text": "Milk", 
  27. "leaf": true, 
  28. "checked": false 
  29. },{ 
  30. "text": "Cereal", 
  31. "leaf": true, 
  32. "checked": false 
  33. },{ 
  34. "text": "Energy foods", 
  35. "cls": "folder", 
  36. "children": [{ 
  37. "text": "Coffee", 
  38. "leaf": true, 
  39. "checked": false 
  40. },{ 
  41. "text": "Red Bull", 
  42. "leaf": true, 
  43. "checked": false 
  44. }] 
  45. }] 
  46. },{ 
  47. "text": "Remodel Project",  
  48. "cls": "folder", 
  49. "children": [{ 
  50. "text": "Finish the budget", 
  51. "leaf": true, 
  52. "checked": false 
  53. },{ 
  54. "text": "Call contractors", 
  55. "leaf": true, 
  56. "checked": false 
  57. },{ 
  58. "text": "Choose design", 
  59. "leaf": true, 
  60. "checked": false 
  61. }] 
  62. }] 

以上所述就是本文的全部内容了,希望大家能够喜欢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选