鍍金池/ 問(wèn)答/HTML5  HTML/ vue如何將兩個(gè)數(shù)組對(duì)象的某一個(gè)字段形成綁定

vue如何將兩個(gè)數(shù)組對(duì)象的某一個(gè)字段形成綁定

如何實(shí)現(xiàn)數(shù)組tags的label屬性與tree.getCheckedNodes()返回?cái)?shù)組的label綁定呢

相關(guān)代碼

<el-dialog title="選項(xiàng)" :visible.sync="dialogFormVisible">
  <el-input placeholder="輸入關(guān)鍵字進(jìn)行過(guò)濾" 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="請(qǐng)選擇">
        <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="請(qǐng)輸入內(nèi)容"></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
    },

我希望效果上可以達(dá)到

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

讓tags的其他屬性跟getchencedNodes的其他屬性不發(fā)生關(guān)系
感覺說(shuō)的很復(fù)雜,這個(gè)問(wèn)題不太好描述

回答
編輯回答
鹿惑

已經(jīng)解決了,根據(jù)別人的提提醒,我發(fā)現(xiàn)這個(gè)綁定是不合理的,所以我通過(guò)getCheckNodes跟tags兩個(gè)數(shù)組循環(huán)對(duì)比,將新添加的push進(jìn)數(shù)組中,將點(diǎn)掉的splice調(diào)

2018年7月20日 13:55