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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM