20e535ac90
#### 新增 - 新增`disabled`配置, 可以禁用多选 - 新增`create`配置, 可以创建条目, 具体见 [创建条目](https://maplemei.gitee.io/xm-select/#/example/XM27) - 方法`warning`新增参数`sustain`, 可以配置是否持续显示 - 新增全局`get`方法, 可以获取多选渲染后的对象 - 新增全局`batch`方法, 可以批量给渲染后的多选执行方法 #### Bug fixes - 修复`update`方法, 会使已选中数据丢失的问题 - 修复`Safari`浏览器下, 搜索框无法聚焦的问题
91 lines
1.7 KiB
Markdown
91 lines
1.7 KiB
Markdown
## 禁用
|
|
|
|
|
|
### 渲染禁用
|
|
|
|
```
|
|
xmSelect.render({
|
|
//...
|
|
disabled: true
|
|
})
|
|
```
|
|
|
|
:::demo
|
|
```html
|
|
<div id="demo1" class="xm-select-demo"></div>
|
|
|
|
<script>
|
|
var demo1 = xmSelect.render({
|
|
el: '#demo1',
|
|
disabled: true,
|
|
data: [
|
|
{name: '张三', value: 1, selected: true},
|
|
{name: '李四', value: 2},
|
|
{name: '王五', value: 3, disabled: true},
|
|
]
|
|
})
|
|
</script>
|
|
```
|
|
:::
|
|
|
|
|
|
### 动态启用禁用
|
|
|
|
:::demo
|
|
```html
|
|
<div id="demo2" class="xm-select-demo"></div>
|
|
<button class="btn" id="demo21">禁用</button>
|
|
<button class="btn" id="demo22">启用</button>
|
|
|
|
<script>
|
|
var demo2 = xmSelect.render({
|
|
el: '#demo2',
|
|
data: [
|
|
{name: '张三', value: 1, selected: true},
|
|
{name: '李四', value: 2},
|
|
{name: '王五', value: 3, disabled: true},
|
|
]
|
|
})
|
|
|
|
document.getElementById('demo21').onclick = function(){
|
|
demo2.update({ disabled: true });
|
|
}
|
|
document.getElementById('demo22').onclick = function(){
|
|
demo2.update({ disabled: false });
|
|
}
|
|
</script>
|
|
```
|
|
:::
|
|
|
|
|
|
### 选完`张三`后禁用
|
|
|
|
:::demo
|
|
```html
|
|
<div id="demo3" class="xm-select-demo"></div>
|
|
<button class="btn" id="demo3-disabled">启用</button>
|
|
|
|
<script>
|
|
var demo3 = xmSelect.render({
|
|
el: '#demo3',
|
|
data: [
|
|
{name: '张三', value: 1},
|
|
{name: '李四', value: 2},
|
|
{name: '王五', value: 3},
|
|
],
|
|
on({ arr, change, isAdd }){
|
|
var hasZS = change.find(item => item.name === '张三');
|
|
if(isAdd && hasZS){
|
|
demo3.update({ disabled: true });
|
|
}
|
|
}
|
|
})
|
|
|
|
//没有做不到, 只有想不到, 把多选玩出花来吧
|
|
document.getElementById('demo3-disabled').onclick = function(){
|
|
demo3.update({ disabled: false });
|
|
}
|
|
</script>
|
|
```
|
|
:::
|