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