需求
使用treeSelect组件多选的时候,不止需要获取到选中值得id,还需要获取label
解决方案
(我在其中还使用了lodash)
HTML
<treeselect
v-model="ruleForm.patenteeIds"
:multiple="true"
:check-strictly="true"
:disable-branch-nodes="true"
:options="patenteeNamesOptions"
:normalizer="normalizer"
@deselect="deSelectPatenteeidsDepart" // 选择项被取消时的函数
@select="selectPatenteeidsDepart" //选择项被选择时的函数
/>
JS
selectPatenteeidsDepart(node, instanceId) {
console.log(this.ruleForm.patenteeNames, "这是开始吗");
if (!this.ruleForm.patenteeNames) {
this.ruleForm.patenteeNames = [];
}
this.ruleForm.patenteeNames.push(node.n);
},
deSelectPatenteeidsDepart(node, instanceId) {
if (!this.ruleForm.patenteeNames) {
this.ruleForm.patenteeNames = [];
}
let index = _.indexOf(this.ruleForm.patenteeNames, node.n);
this.ruleForm.patenteeNames.splice(index, 1);
}