可编辑可选择树视图插件 jQuery TreeEditor

  • 源码大小:24.31KB
  • 所需积分:1积分
  • 源码编号:19JP-3328
  • 浏览次数:628次
  • 最后更新:2023年06月01日
  • 所属栏目:其他
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

TreeEditor是一个jQuery树插件,用于从JavaScript数组动态生成可编辑、可检查和分层的树结构。

特征:

  • 最小的清洁接口。
  • 每个节点都是可编辑的。
  • 插入/删除节点。
  • 通过复选框或单选按钮选择节点。
  • 平滑折叠/展开动画。

如何使用它:

1.为树创建一个空的DIV容器。

  1. <div class="example"></div>

2.在文档中加载jQuery TreeEditor插件的文件。

  1. <!-- jQuery Is Required -->
  2. <script src="/path/to/cdn/jquery.min.js"></script>
  3.  
  4. <!-- jQuery TreeEditor -->
  5. <script src="js/dinamp.treeeditor.js"></script>
  6. <link rel="stylesheet" href="css/treeeditor.css" />

3.在JS数组中定义分层数据,如下所示:

  1. var data = [
  2. {
  3. title: "Warehouse",
  4. children: [
  5. {
  6. title:"Shelfs A",
  7. children: [
  8. {title:"Shelf A1"},
  9. {title:"Shelf A2"},
  10. {title:"Shelf A3"},
  11. {title:"Shelf A4"}
  12. ]
  13. },
  14. {
  15. title:"Shelfs B",
  16. children: [
  17. {title:"Shelf B1"},
  18. {title:"Shelf B2"}
  19. ]
  20. },
  21. {title:"Ground"}
  22. ]
  23. }
  24. ];

3.初始化插件以生成一个基本树。

  1. const myTree = new DinampTreeEditor('.example').setData(data);

4.将单选按钮或复选框添加到树节点。

  1. const myTree = new DinampTreeEditor('.example').setData(data).set({
  2. radios: true,
  3. oncheck: function(state, text, path) {
  4. // do something
  5. }
  6. });;
  1. const myTree = new DinampTreeEditor('.example').setData(data).set({
  2. checkboxes: true,
  3. onchange: function(tree) {
  4. // JSON.stringify(tree.getData());
  5. }
  6. });;

5.禁用“可编辑”功能。

  1. const myTree = new DinampTreeEditor('.example').setData(data).set({
  2. editable: false,
  3. });;

6.在页面加载时折叠所有节点。

  1. const myTree = new DinampTreeEditor('.example').setData(data).set({
  2. extended: false,
  3. });;

预览截图