How does element-ui determine whether multiple selections are selected by default according to the checked in the data?

1. To judge whether to be selected by default according to whether checked is 1 (1 is selected, 2 is unselected). The problem now is that if both checked are 1, only the last one will be executed, and now the desired effect is: as long as checked is 1, it will be selected by default

.
<template>
  <div>
    <el-tree
      :data="data2"
      show-checkbox
      default-expand-all
      node-key="checked"
      ref="tree"
      highlight-current
      :props="defaultProps">
    </el-tree>

    <div class="buttons">
      <el-button @click="setCheckedNodes"> node </el-button>
    </div>
  </div>
</template>

<script>
  export default {
    methods: {
      setCheckedNodes() {
        console.log(this.$refs.tree)
        this.$refs.tree.setCheckedNodes([{
          checked: 1
        }]);
      }
    },
    data() {
      return {
        data2: [{
          checked: 1,
          label: " 1",
          children: [{
            checked: 0,
            label: " 1-1",
            children: [{
              checked: 0,
              label: " 1-1-1"
            }, {
              checked: 0,
              label: " 1-1-2"
            }]
          }]
        }, {
          checked: 1,
          label: " 2",
          children: [{
            checked: 0,
            label: " 2-1"
          }, {
            checked: 0,
            label: " 2-2"
          }]
        }, {
          checked: 0,
          label: " 3",
          children: [{
            checked: 0,
            label: " 3-1"
          }, {
            checked: 0,
            label: " 3-2"
          }]
        }],
        defaultProps: {
          children: "children",
          label: "label"
        }
      };
    }
  };
</script>


Mar.22,2021

visually observe that your node-key settings are wrong.

document:

sets the default expanded and selected nodes by default-expanded-keys and default-checked-keys , respectively. It is important to note that node-key must be set at this time, whose value is a field name in the node data, which is unique throughout the tree.

official example:

<el-tree
  :data="data2"
  show-checkbox
  node-key="id"
  :default-expanded-keys="[2, 3]"
  :default-checked-keys="[5]"
  :props="defaultProps">
</el-tree>

<script>
  export default {
    data() {
      return {
        data2: [{
          id: 1,
          label: ' 1',
          children: [{
            id: 4,
            label: ' 1-1',
            children: [{
              id: 9,
              label: ' 1-1-1'
            }, {
              id: 10,
              label: ' 1-1-2'
            }]
          }]
        }, {
          id: 2,
          label: ' 2',
          children: [{
            id: 5,
            label: ' 2-1'
          }, {
            id: 6,
            label: ' 2-2'
          }]
        }, {
          id: 3,
          label: ' 3',
          children: [{
            id: 7,
            label: ' 3-1'
          }, {
            id: 8,
            label: ' 3-2'
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      };
    }
  };
</script>

ask whether to render


according to the checked attribute of data2 data when rendering tree. How do you solve this problem

?
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e44f81-44b06.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e44f81-44b06.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?