美文网首页
BootStrapTreeView使用

BootStrapTreeView使用

作者: Janny_a705 | 来源:发表于2018-10-01 16:22 被阅读0次

    1、Java数据结构(供参考)

    public class BSTreeNode {

    private String pId;

    private String text;

     private Listnodes = new ArrayList<>();

    private List tags = new ArrayList<>();

     private String type;

    }

    2、JS动态加载(复制后,在线格式化即可)

    $.ajax({ type: "POST", url: "http://localhost:8888/app/getSceneTree", contentType: 'text/plain', dataType: "json", success: function(data) { deleteEmptyProperty(data); $searchableTree = $('#treeview-searchable').treeview({ data: data, levels:0, onhoverColor:'#d9edf7', emptyIcon: 'glyphicon glyphicon-leaf', onNodeSelected: function (event, data) { alert("aa");//节点被选中时候触发的操作 } }); $("ul.list-group li:first").click(); }, error: function() {} })

    3、deleteEmptyProperty该方法可以去掉Json中的空串和空对象,树的叶子节点没有+号

    function deleteEmptyProperty(object) { for (var i in object) { var value = object[i]; if (typeof value === 'object') { if (Array.isArray(value)) { if (value.length == 0) { delete object[i]; continue; } } this.deleteEmptyProperty(value); if (this.isEmpty(value)) { delete object[i]; } } else { if (value === '' || value === null || value === undefined) { delete object[i]; } else {} } } } function isEmpty(object) { for (var name in object) { return false; } return true; }

    相关文章

      网友评论

          本文标题:BootStrapTreeView使用

          本文链接:https://www.haomeiwen.com/subject/bzenoftx.html