vue如何将两个数组对象的某一个字段形成绑定

如何实现数组tags的label属性与tree.getCheckedNodes()返回数组的label绑定呢

相关代码

<el-dialog title="选项" :visible.sync="dialogFormVisible">
  <el-input placeholder="输入关键字进行过滤" v-model="filterText"></el-input>
  <el-tree class="filter-tree" :data="anaphylaxis" :props="defaultProps" node-key="label"  show-checkbox :filter-node-method="filterNode" ref="tree2"></el-tree>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="setitem()">确 定</el-button>
  </div>
</el-dialog>
  <el-table :data="filterAnaylistList3" class="tb-edit" border highlight-current-row>
  <el-table-column type="index" label="#" width="50" min-width="50">
  </el-table-column>
  <el-table-column prop="label" label="药品名称">
  </el-table-column>
  <el-table-column prop="value" label="症状">
    <template slot-scope="scope">
      <el-select v-model="scope.row.value"  multiple filterable placeholder="请选择">
        <el-option-group
          v-for="group in symptom"
          :key="group.label"
          :label="group.label">
          <el-option
            v-for="item in group.children"
            :key="item.label"
            :label="item.label"
            :value="item.label"
            >
          </el-option>
        </el-option-group>
      </el-select>
       <span >{{scope.row.value | capitalize}}</span>
    </template>
  </el-table-column>
  <el-table-column prop="beizhu" label="备注">
    <template slot-scope="scope">
      <el-input v-model="scope.row.beizhu" placeholder="请输入内容"></el-input>
      <span>{{scope.row.beizhu}}</span>
    </template>
  </el-table-column>
   <el-table-column prop="type" label="类型">
  </el-table-column>
  </el-table>
    open () {
      this.dialogFormVisible = true
      setTimeout(() => {
        this.$refs.tree2.setCheckedNodes(this.tags)
      }, 0)
    },
    setitem () {
      console.log(this.tags.label)
      this.tags = this.$refs.tree2.getCheckedNodes()
      this.dialogFormVisible = false
    },

我希望效果上可以达到

      this.tags.label = this.$refs.tree2.getCheckedNodes().label

让tags的其他属性跟getchencedNodes的其他属性不发生关系
感觉说的很复杂,这个问题不太好描述

阅读 3.5k
1 个回答
新手上路,请多包涵

已经解决了,根据别人的提提醒,我发现这个绑定是不合理的,所以我通过getCheckNodes跟tags两个数组循环对比,将新添加的push进数组中,将点掉的splice调

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题