mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
feat(TreeSelect): add max prop (#2004)
This commit is contained in:
parent
8eeb74c3a7
commit
9dba47ddb2
@ -16,6 +16,7 @@
|
|||||||
active-id="{{ activeIdMulti }}"
|
active-id="{{ activeIdMulti }}"
|
||||||
bind:click-item="onClickItemMulti"
|
bind:click-item="onClickItemMulti"
|
||||||
bind:click-nav="onClickNavMulti"
|
bind:click-nav="onClickNavMulti"
|
||||||
|
max="2"
|
||||||
content-item-class="content-item-class"
|
content-item-class="content-item-class"
|
||||||
></van-tree-select>
|
></van-tree-select>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
@ -97,6 +97,7 @@ Page({
|
|||||||
| items | 分类显示所需的数据 | *Array* | `[]` | - |
|
| items | 分类显示所需的数据 | *Array* | `[]` | - |
|
||||||
| main-active-index | 左侧选中项的索引 | *number* | `0` | - |
|
| main-active-index | 左侧选中项的索引 | *number* | `0` | - |
|
||||||
| active-id | 右侧选中项的 id,支持传入数组 | *string \| number \| Array* | `0` | - |
|
| active-id | 右侧选中项的 id,支持传入数组 | *string \| number \| Array* | `0` | - |
|
||||||
|
| max | 右侧项最大选中个数 | *number* | *Infinity* | - |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@ -23,6 +23,10 @@ VantComponent({
|
|||||||
maxHeight: {
|
maxHeight: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 300
|
value: 300
|
||||||
|
},
|
||||||
|
max: {
|
||||||
|
type: Number,
|
||||||
|
value: Infinity
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -51,7 +55,13 @@ VantComponent({
|
|||||||
// 当一个子项被选择时
|
// 当一个子项被选择时
|
||||||
onSelectItem(event: Weapp.Event) {
|
onSelectItem(event: Weapp.Event) {
|
||||||
const { item } = event.currentTarget.dataset;
|
const { item } = event.currentTarget.dataset;
|
||||||
if (!item.disabled) {
|
const isArray = Array.isArray(this.data.activeId);
|
||||||
|
// 判断有没有超出右侧选择的最大数
|
||||||
|
const isOverMax = isArray && (this.data.activeId.length >= this.data.max);
|
||||||
|
// 判断该项有没有被选中, 如果有被选中,则忽视是否超出的条件
|
||||||
|
const isSelected = isArray ? this.data.activeId.indexOf(item.id) > -1 : this.data.activeId === item.id;
|
||||||
|
|
||||||
|
if (!item.disabled && (!isOverMax || isSelected)) {
|
||||||
this.$emit('click-item', item);
|
this.$emit('click-item', item);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user