mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-09-01 21:59:45 +08:00
parent
cc783fc86f
commit
d605c45190
@ -35,12 +35,13 @@ VantComponent({
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
items() {
|
items() {
|
||||||
this.updateSubItems();
|
this.updateSubItems().then(() => {
|
||||||
this.updateMainHeight();
|
this.updateMainHeight();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
maxHeight() {
|
maxHeight() {
|
||||||
this.updateItemHeight();
|
this.updateItemHeight(this.data.subItems);
|
||||||
this.updateMainHeight();
|
this.updateMainHeight();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -67,31 +68,29 @@ VantComponent({
|
|||||||
|
|
||||||
// 更新子项列表
|
// 更新子项列表
|
||||||
updateSubItems() {
|
updateSubItems() {
|
||||||
const selectedItem = this.data.items[this.data.mainActiveIndex] || {};
|
const { items, mainActiveIndex } = this.data;
|
||||||
|
const { children = [] } = items[mainActiveIndex] || {};
|
||||||
|
|
||||||
this.set({ subItems: selectedItem.children || [] });
|
this.updateItemHeight(children);
|
||||||
|
return this.set({ subItems: children });
|
||||||
this.updateItemHeight();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 更新组件整体高度,根据最大高度和当前组件需要展示的高度来决定
|
// 更新组件整体高度,根据最大高度和当前组件需要展示的高度来决定
|
||||||
updateMainHeight() {
|
updateMainHeight() {
|
||||||
|
const { items = [], subItems = [] } = this.data;
|
||||||
const maxHeight = Math.max(
|
const maxHeight = Math.max(
|
||||||
this.data.items.length * ITEM_HEIGHT,
|
items.length * ITEM_HEIGHT,
|
||||||
this.data.subItems.length * ITEM_HEIGHT
|
subItems.length * ITEM_HEIGHT
|
||||||
);
|
);
|
||||||
|
|
||||||
this.set({ mainHeight: Math.min(maxHeight, this.data.maxHeight) });
|
this.set({ mainHeight: Math.min(maxHeight, this.data.maxHeight) });
|
||||||
},
|
},
|
||||||
|
|
||||||
// 更新子项列表高度,根据可展示的最大高度和当前子项列表的高度决定
|
// 更新子项列表高度,根据可展示的最大高度和当前子项列表的高度决定
|
||||||
updateItemHeight() {
|
updateItemHeight(subItems) {
|
||||||
this.set({
|
const itemHeight = Math.min(subItems.length * ITEM_HEIGHT, this.data.maxHeight);
|
||||||
itemHeight: Math.min(
|
|
||||||
this.data.subItems.length * ITEM_HEIGHT,
|
return this.set({ itemHeight });
|
||||||
this.data.maxHeight
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
wx:for="{{ subItems }}"
|
wx:for="{{ subItems }}"
|
||||||
wx:key="item.id"
|
wx:key="id"
|
||||||
class="van-ellipsis van-hairline--bottom content-item-class {{ utils.bem('tree-select__item', { active: activeId === item.id, disabled: item.disabled }) }} {{ activeId === item.id ? 'content-active-class' : '' }} {{ item.disabled ? 'content-disabled-class' : '' }}"
|
class="van-ellipsis van-hairline--bottom content-item-class {{ utils.bem('tree-select__item', { active: activeId === item.id, disabled: item.disabled }) }} {{ activeId === item.id ? 'content-active-class' : '' }} {{ item.disabled ? 'content-disabled-class' : '' }}"
|
||||||
data-item="{{ item }}"
|
data-item="{{ item }}"
|
||||||
bind:tap="onSelectItem"
|
bind:tap="onSelectItem"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user