2019-10-20 18:01:27 +08:00
|
|
|
## 下拉树
|
|
|
|
|
2019-11-19 20:13:50 +08:00
|
|
|
### tree
|
2019-10-20 18:01:27 +08:00
|
|
|
|
2019-11-19 20:13:50 +08:00
|
|
|
默认配置
|
|
|
|
|
|
|
|
```
|
|
|
|
tree: {
|
|
|
|
//是否显示树状结构
|
|
|
|
show: false,
|
|
|
|
//是否展示三角图标
|
|
|
|
showFolderIcon: true,
|
|
|
|
//是否显示虚线
|
|
|
|
showLine: false,
|
|
|
|
//间距
|
|
|
|
indent: 20,
|
|
|
|
//默认展开节点的数组
|
|
|
|
expandedKeys: [],
|
2019-11-21 20:06:27 +08:00
|
|
|
//是否严格遵守父子模式
|
|
|
|
strict: true,
|
2019-11-19 20:13:50 +08:00
|
|
|
},
|
|
|
|
```
|
2019-10-20 18:01:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
:::demo
|
|
|
|
```html
|
|
|
|
|
|
|
|
<div id="demo1" class="xm-select-demo"></div>
|
|
|
|
|
2019-11-19 20:13:50 +08:00
|
|
|
<br/>
|
|
|
|
<div class="layui-form">
|
|
|
|
<input type="checkbox" name="showFolderIcon" lay-filter="showFolderIcon" lay-skin="primary" title="是否展示三角图标" checked>
|
|
|
|
<input type="checkbox" name="showLine" lay-filter="showLine" lay-skin="primary" title="是否显示虚线" checked>
|
2019-11-21 20:06:27 +08:00
|
|
|
<input type="checkbox" name="strict" lay-filter="strict" lay-skin="primary" title="严格父子结构" checked>
|
2019-11-19 20:13:50 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div style="margin-top: 20px">间距</div>
|
|
|
|
<div id="slideTest1"></div>
|
|
|
|
|
|
|
|
|
2019-10-20 18:01:27 +08:00
|
|
|
<script>
|
2019-11-19 20:13:50 +08:00
|
|
|
layui.form.render();
|
2019-10-20 18:01:27 +08:00
|
|
|
|
2019-11-21 20:06:27 +08:00
|
|
|
['showFolderIcon', 'showLine', 'strict'].forEach(function(key){
|
|
|
|
layui.form.on('checkbox('+key+')', function(data){
|
|
|
|
var treeConfig = {};
|
|
|
|
treeConfig[key] = data.elem.checked;
|
|
|
|
demo1.update({
|
|
|
|
tree: treeConfig
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2019-11-19 20:13:50 +08:00
|
|
|
layui.slider.render({
|
|
|
|
elem: '#slideTest1',
|
|
|
|
min: 10,
|
|
|
|
max: 100,
|
|
|
|
showstep: true,
|
|
|
|
input: true,
|
|
|
|
tips: true,
|
|
|
|
value: 20,
|
|
|
|
change: function(value){
|
|
|
|
demo1.update({
|
|
|
|
tree: {
|
|
|
|
indent: value
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2019-10-20 18:01:27 +08:00
|
|
|
});
|
|
|
|
|
2019-11-19 20:13:50 +08:00
|
|
|
var demo1 = xmSelect.render({
|
|
|
|
el: '#demo1',
|
|
|
|
autoRow: true,
|
2019-11-25 15:17:08 +08:00
|
|
|
filterable: true,
|
2019-11-19 20:13:50 +08:00
|
|
|
tree: {
|
|
|
|
show: true,
|
|
|
|
showFolderIcon: true,
|
|
|
|
showLine: true,
|
|
|
|
indent: 20,
|
|
|
|
expandedKeys: [ -3 ],
|
|
|
|
},
|
2019-11-25 15:17:08 +08:00
|
|
|
filterable: true,
|
2019-11-19 20:13:50 +08:00
|
|
|
height: 'auto',
|
|
|
|
data(){
|
|
|
|
return [
|
|
|
|
{name: '销售员', value: -1, disabled: true, children: [
|
2019-11-20 18:47:49 +08:00
|
|
|
{name: '张三1', value: 1, selected: true, children: []},
|
2019-11-19 20:13:50 +08:00
|
|
|
{name: '李四1', value: 2, selected: true},
|
|
|
|
{name: '王五1', value: 3, disabled: true},
|
|
|
|
]},
|
|
|
|
{name: '奖品', value: -2, children: [
|
|
|
|
{name: '奖品3', value: -3, children: [
|
|
|
|
{name: '苹果3', value: 14, selected: true},
|
|
|
|
{name: '香蕉3', value: 15},
|
|
|
|
{name: '葡萄3', value: 16},
|
|
|
|
]},
|
|
|
|
{name: '苹果2', value: 4, selected: true, disabled: true},
|
|
|
|
{name: '香蕉2', value: 5},
|
|
|
|
{name: '葡萄2', value: 6},
|
|
|
|
]},
|
|
|
|
]
|
|
|
|
}
|
2019-10-20 18:01:27 +08:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
:::
|
2019-11-22 20:33:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
### 懒加载的树
|
|
|
|
|
|
|
|
```
|
|
|
|
tree: {
|
|
|
|
show: true,
|
|
|
|
expandedKeys: [ -1 ],
|
|
|
|
//开启懒加载
|
|
|
|
lazy: true,
|
|
|
|
//加载方法
|
|
|
|
load: function(item, cb){
|
|
|
|
//item: 点击的节点, cb: 回调函数
|
|
|
|
//这里模拟ajax
|
|
|
|
setTimeout(function(){
|
|
|
|
var name = item.name + 1;
|
|
|
|
cb([
|
|
|
|
{name: item.name + 1, value: item.value + '1', children: [] },
|
|
|
|
{name: item.name + 2, value: item.value + '2' },
|
|
|
|
])
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
```
|
|
|
|
|
|
|
|
:::demo
|
|
|
|
```html
|
|
|
|
<div id="demo2" class="xm-select-demo"></div>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var demo2 = xmSelect.render({
|
|
|
|
el: '#demo2',
|
|
|
|
autoRow: true,
|
|
|
|
tree: {
|
|
|
|
show: true,
|
|
|
|
showFolderIcon: true,
|
|
|
|
showLine: true,
|
|
|
|
indent: 20,
|
|
|
|
expandedKeys: [ -1 ],
|
|
|
|
lazy: true,
|
|
|
|
load: function(item, cb){
|
|
|
|
setTimeout(function(){
|
2019-11-23 20:10:47 +08:00
|
|
|
if(item.name.endsWith('2')){
|
|
|
|
return cb([]);
|
|
|
|
}
|
2019-11-22 20:33:17 +08:00
|
|
|
cb([
|
|
|
|
{name: item.name + 1, value: item.value + '1', children: [] },
|
2019-11-23 20:10:47 +08:00
|
|
|
{name: item.name + 2, value: item.value + '2', children: [] },
|
2019-11-22 20:33:17 +08:00
|
|
|
])
|
|
|
|
}, 500)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
height: 'auto',
|
|
|
|
data(){
|
|
|
|
return [
|
|
|
|
{name: '销售员', value: -1, children: [
|
2019-11-23 20:10:47 +08:00
|
|
|
{name: '张三', value: 100, selected: true, children: []},
|
2019-11-22 20:33:17 +08:00
|
|
|
{name: '李四1', value: 2, selected: true},
|
|
|
|
{name: '王五1', value: 3, disabled: true},
|
|
|
|
]},
|
|
|
|
{name: '奖品', value: -2, children: [
|
|
|
|
{name: '奖品3', value: -3, children: [
|
|
|
|
{name: '苹果3', value: 14, selected: true},
|
|
|
|
{name: '香蕉3', value: 15},
|
|
|
|
{name: '葡萄3', value: 16},
|
|
|
|
]},
|
|
|
|
{name: '苹果2', value: 4, selected: true, disabled: true},
|
|
|
|
{name: '香蕉2', value: 5},
|
|
|
|
{name: '葡萄2', value: 6},
|
|
|
|
]},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
:::
|