Back to Layui

Options

docs/treeTable/detail/options.md

2.13.66.1 KB
Original Source
<table class="layui-table"> <colgroup> <col width="150"> <col> </colgroup> <thead> <tr> <th>属性名</th> <th>描述</th> </tr> </thead> <tbody> <tr> <td>tree</td> <td>

treeTable 组件的特定属性集,包含以下「子成员集」:

属性描述
customName自定义属性名的集合
view视图相关的属性集合
data数据相关的属性集合
async异步相关的属性集合
callback事件回调相关的属性集合

用法如下:

js
treeTable.render({
  elem: '',
  tree: { // treeTable 特定属性集
    customName: {},
    data: {},
    view: {},
    async: {},
    callback: {}
  },
  // 其他 table 属性
});
</td> </tr> <tr> <td>tree.customName</td> <td> <div id="options.tree.customName" lay-pid="options" class="ws-anchor">

自定义属性名的集合,包含以下成员:

</div>
属性描述类型默认值
children自定义「子节点集合」的属性名stringchildren
isParent自定义「是否属于父节点」的属性名stringisParent
name自定义「节点」属性名stringname
id自定义「节点索引」属性名stringid
pid自定义「父节点索引」属性名stringparentId
icon自定义图标的属性名称stringicon
</td> </tr> <tr> <td>tree.view</td> <td> <div id="options.tree.view" lay-pid="options" class="ws-anchor">

视图相关的属性集合,包含以下成员:

</div>
属性描述类型默认值
indent层级缩进量number14
flexIconClose自定义关闭时的折叠按钮图标string-
flexIconOpen自定义打开时的折叠按钮图标string-
showIcon是否显示节点图标booleantrue
icon自定义节点图标。若设置了该属性或数据中有该字段信息,不管打开还是关闭都以这个图标的值为准string-
iconClose自定义关闭时的节点图标string-
iconOpen自定义打开时的节点图标string-
iconLeaf自定义叶子节点的图标string-
showFlexIconIfNotParent若非父节点时,是否显示折叠图标booleanfalse
dblClickExpand双击节点时,是否自动展开父节点booleantrue
expandAllDefault <sup>2.8.7+</sup>是否默认展开全部节点booleanfalse

自定义图标支持 HTML 字符串和图标类名。例如:

  • '<i class="i-svg-spinners-blocks-wave"></i>'
  • 'layui-icon layui-icon-addition'
</td> </tr> <tr> <td>tree.data</td> <td> <div id="options.tree.data" lay-pid="options" class="ws-anchor">

数据相关的属性集合,包含以下成员:

</div>
属性描述类型默认值
isSimpleData是否使用平铺数据格式(Array)booleanfalse
rootPid用于设置根节点的 pid 属性值stringnull
cascade用于设置复选的级联方式。支持以下可选值:<ul><li><code>all</code> : 所有节点联动</li><li><code>parent</code> : 仅对父节点联动</li><li><code>children</code> : 仅对子节点联动</li><li><code>none</code> <sup>2.8.16+</sup> : 不做任何联动</li></ul>stringall
</td> </tr> <tr> <td>tree.async</td> <td> <div id="options.tree.async" lay-pid="options" class="ws-anchor">

异步相关的属性集合,包含以下成员:

</div>
属性描述类型默认值
enable是否开启异步加载模式。只有开启时 async 的其他属性选项才有效。 注意: 异步加载子节点不应跟 simpleData 同时开启,可以是 url+simpleData 的方式,获取完整的简单数据进行转换。若开启异步加载模式,即表示按需异步加载子节点。booleanfalse
url异步加载的接口,可以根据需要设置与顶层接口不同的接口,若相同可不设置该属性string-
format用于处理异步子节点数据的回调函数,该属性优先级高于 async.url 属性。用法详见下文。function-
type请求的接口类型,设置可缺省同上string-
contentType提交参数的数据类型,设置可缺省同上string-
headers提交请求头,设置可缺省同上object-
where提交参数的数据,设置可缺省同上object-
autoParam自动参数,可以根据配置项以及当前节点的数据传参,如: ['type', 'age=age', 'parentId=id'] ,那么其请求参数将包含: {type: '父节点 type', age: '父节点 age', parentId: '父节点 id'}array-
<div id="options.tree.async.format" class="ws-anchor">

format 示例

</div>
treeTable.render({
  elem: '',
  tree: {
    enable: true,
    async: {
      format: function(trData, options, callback){
        // trData 为行数据、options 为 treeTable 属性选项
        // callbacck 为子节点的渲染函数
        // 可利用该函数对子节点数据进行异步请求或其他格式化处理
        var nodeList = [
          {id: 111, name: '子节点1'},
          {id: 333, name: '子节点3'}
        ];
        callback(nodeList);
      }
    }
  }
})
</td> </tr> <tr> <td>tree.callback</td> <td> <div id="options.tree.callback" lay-pid="options" class="ws-anchor">

事件回调相关的属性集合,包含以下成员:

</div>
属性描述
beforeExpand展开前回调函数。可以在展开或者关闭之前调用,传入当前表格 id ,当前操作的行数据以及要展开或关闭的状态,若回调返回 false 则取消该次操作。 返回的参数包含: function(tableId, trData, expandFlag){ console.log(arguments); }
onExpand展开或关闭后的回调函数,返回参数同 beforeExpand
</td> </tr> </tbody> </table>