From 8dae2c5feb1aee0c666a7176fa23c95ad9f59acc Mon Sep 17 00:00:00 2001 From: smallwei <1634566606@qq.com> Date: Mon, 16 Jul 2018 00:41:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(tree):=20=E5=8A=A0=E5=85=A5props=20?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E9=80=82=E9=85=8D=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/tree.html | 7 ++++++- src/lay/modules/tree.js | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/examples/tree.html b/examples/tree.html index ed23627..ea5f801 100644 --- a/examples/tree.html +++ b/examples/tree.html @@ -33,6 +33,11 @@ //,target: '_blank' //是否新选项卡打开(比如节点返回href才有效) , drag: true, + props:{ + name: 'name', + id: 'id', + children:'children' + }, change:function(val){ console.group('change event') console.log('Array') @@ -53,7 +58,7 @@ console.log(elem); console.log('dom add event') var item ={ - name: '测试节点', + name: '测试节点'+new Date().getTime(), id:-1 } add(item) diff --git a/src/lay/modules/tree.js b/src/lay/modules/tree.js index 95e8540..12204fd 100644 --- a/src/lay/modules/tree.js +++ b/src/lay/modules/tree.js @@ -11,12 +11,23 @@ layui.define('jquery', function(exports) { var $ = layui.$, hint = layui.hint(); + //勾选集合 + var changeList = []; + //变量别名 + var props ={ + name: 'name', + id: 'id', + children:'children' + }; + var enterSkin = 'layui-tree-enter', Tree = function(options) { this.options = options; + this.props = this.options.props || props; + this.nameKey = this.props.name || props.name; + this.idKey = this.props.id || props.id; + this.childrenKey = this.props.children || props.children; }; - //勾选集合 - var changeList = []; //图标 var icon = { arrow: ['', ''] //箭头 @@ -44,13 +55,13 @@ layui.define('jquery', function(exports) { var nodes = children || options.nodes; layui.each(nodes, function(index, item) { - var hasChild = item.children && item.children.length > 0; + var hasChild = item[that.childrenKey] && item[that.childrenKey].length > 0; var ul = $('