iview / iview-admin

Vue 2.0 admin management system template based on iView
https://admin.iviewui.com/
MIT License
16.48k stars 4.85k forks source link

树形表格,动态新增子节点,无法渲染 #1275

Open guowei opened 5 years ago

guowei commented 5 years ago

例如:

<tree-table expand-key="sex" :expand-type="false" :selectable="false" :columns="columns" :data="data" >
        <template slot="likes" slot-scope="scope">
          <Button @click="handle(scope)">123</Button>
        </template>
      </tree-table>

data: [
          {
            name: 'Jack',
            sex: 'male',
            likes: ['football', 'basketball'],
            score: 10
       }
]

methods: {
    handle (scope) {
      const aa = scope;
      const newChild = {
          name: '子节点',
          sex: 'male',
          likes: ['football', 'basketball'],
          score: 20,
          children: [],
        };

        if (!aa.row.children) {
          console.log('>>>>>');
          this.$set(aa.row, 'children', []);
          aa.row.children.push(newChild);  //  表格无法渲染,新加的 childeren
        } else {
          aa.row.children.push(newChild);
        }
    }
  }
NNNNzs commented 5 years ago

你在scope里面加当然没用,要在源数据data里面加才行