sorting - Is it possible to sort Vuetify multiple selection on change?
问题描述
I have a multiple selection Vue component that feeds items to display in an input box. As of now, it adds items based on the order of selection, but I wanted to template it to sort by sort_order after selection (objective_id, category_id, objective_code, objective_description, disabled_flag, sort_order are all passed into objectiveArray object). Is this possible to do in Vuetify?
<v-flex xs12>
<v-tooltip :disabled="!showTooltip" top>
<v-select
slot="activator"
class="objective-select"
v-model="record.objectives"
:items="objectiveArray"
label="Objective(s)"
placeholder="Enter Objective(s)"
:error-messages="objectiveErrors"
:return-object="true"
item-text="objectiveDescription"
multiple
@blur="v.$each[index].objectives.$touch()">
<template v-slot:selection="{ item, index }">
<v-chip
color="primary"
dark
class="objective-chip"
:class="{
mobile:isMobile,
tablet:isTablet
}">
<span>{{ item.objectiveDescription }}</span>
</v-chip>
</template>
</v-select>
<span>Select one or more procedure objective(s)</span>
</v-tooltip>
</v-flex>
解决方案
您可以在事件触发v-model
后对绑定进行排序。@input
这是一个简单的例子:
<template>
<div>
<v-select
v-model="selected"
:items="items"
item-text="id"
item-value="id"
multiple
@input="sortSelection"
return-object
>
</v-select>
</div>
</template>
<script>
export default {
data: () => ({
selected: [],
items: [{id:1},{id:2},{id:3},{id:4},{id:5},{id:6}]
}),
methods: {
sortSelection() {
this.selected.sort((x, y) => {
if (x.id > y.id) return 1
else if (y.id > x.id) return -1
else return 0
})
}
}
}
</script>
只要您sort_order
是一个数字,您就可以将其替换为id
我示例中的字段。
推荐阅读
- angular - 带有来自可观察对象的标头值的 httpinteceptor
- c# - 对话的 Outlook 收件箱对话视图的项目条件是什么?
- php - php连接标识符和Oracle v$session之间的联系
- ruby-on-rails - 错误信息:输入/输出错误@io_write -
- html - 在反应中导入图像时遇到问题
- security - 我应该为 Kubernetes 禁用 TCP 时间戳吗?
- python - 两个异步任务 - 一个依赖于 python 中的另一个
- excel - Excel 到 Word - 通过 ActiveX 复选框使用标题、标题 1 格式化
- charts - 不同颜色的酒吧
- excel - 索引匹配多个条件以查找之前的单元格(Excel)