需求
使用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);
}