1. 程式人生 > 其它 >treeSelect 多選如何獲取選中的對應值的label

treeSelect 多選如何獲取選中的對應值的label

需求

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