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);
    }
posted @ 2021-08-12 14:06  是天天呀  阅读(2346)  评论(0)    收藏  举报