current position:Home>Vue nested loop array, select one of them and add the selected style

Vue nested loop array, select one of them and add the selected style

2022-04-29 08:50:35囍囍囍囍囍囍囍囍囍囍 A

<el-collapse-item
  v-for="(item, i) in stationList"
          :key="i"
          :name="item.name"
        >
          <template slot="title">
            <span class="title">{
   { item.name }}</span>
          </template>
          <ul class="treeClass">
            <li
              v-for="(items, k) in item.list"
              :key="k"
              @click="selectStation(items, k, i)"
              :class="[k == stationList[i].selectIndex ? 'activeClass' : '']"
            >
              <span>{
   { items.stationName }}</span>
            </li>
          </ul>
        </el-collapse-item>
 methods: {
    findListByParamMethods() {
      findListByParam({ stationName: "" }).then((res) => {
        let stationList = [];
        if (JSON.stringify(res) !== "{}") {
          for (let i in res) {
            stationList.push({
              name: i,
              list: res[i],
            });
          }
        }
        this.stationList = stationList;
        this.stationList.map((item) => {
          item.selectIndex = -1;
        });
        this.activeNames = stationList.map((item) => item.name);
        // this.selectStation(this.stationList[0].list[0], 0, 0);
      });
    },
    selectStation(items, k, i) {
      if (this.type === 2) {
        this.$emit("selectStation", this.checkedList);
      } else {
        let stationIndex = this.stationList[i];
        stationIndex.selectIndex = k;
        this.$set(this.stationList, i, stationIndex);
        this.$emit("selectStation", items);
      }
    },
  },

copyright notice
author[囍囍囍囍囍囍囍囍囍囍 A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290621251144.html