第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么每當(dāng)單擊父表的行時,子表(切換表)都會重復(fù)?

為什么每當(dāng)單擊父表的行時,子表(切換表)都會重復(fù)?

達令說 2022-09-23 21:54:58
我試圖做一個包含國家GDP的表格。當(dāng)任何人單擊州行時,將顯示子表(地區(qū) GDP 表)。它工作正常,但子表在重復(fù)。我制作了一個切換功能來控制子表的隱藏/顯示。誰能找出為什么子表重復(fù)?解決方案將不勝感激。運行代碼段以正確理解問題。  var app = new Vue({  el: "#app",  data(){    return {    opened:[],    stateGDP: [        { State: "Rajasthan", "1999-00": "2547", "2000-01": "3679",Id:"23" },        { State: "Orissa", "1999-00": "38714", "2000-01": "38814",Id:"24" }      ],      DistrictGDP: [        {          State: "Rajasthan",          District: "Jaipur",          "1999-00": "2547",          "2000-01": "3679",          Id:"23"        },        {          State: "Rajasthan",          District: "Jodhpur",          "1999-00": "2557",          "2000-01": "3639",          Id:"23"        },        {          State: "Orissa",          District: "Bhubaneswar",          "1999-00": "1983",          "2000-01": "2068",          Id:"24"        },        {          State: "Orissa",          District: "Puri",          "1999-00": "1923",          "2000-01": "2008",          Id:"24"        }      ]      }    },  methods:{    toggle:function(Id) {    const index = this.opened.indexOf(Id);    if (index > -1) {      this.opened.splice(index, 1)    } else {      this.opened.push(Id)    } }}})<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script><div id="app">        <div class="table">          <table class="table-fill">            <thead>            <tr>    <th class="text-center">State/UT</th>    <th class="text-center">1999-00</th>    <th class="text-center">2000-01</th></tr></thead>  <template v-for="row in stateGDP">    <tr @click="toggle(row.Id)" :class="{ opened: opened.includes(row.Id) }">      <td>{{ row.State }}</td>      <td>{{ row['1999-00'] }}</td>      <td>{{ row['2000-01'] }}</td>    </tr>    <template v-for="(xy, indexStop) in DistrictGDP" v-if="opened.includes(row.Id) && row.Id==xy.Id">    <thead>    <tr>
查看完整描述

1 回答

?
紫衣仙女

TA貢獻1839條經(jīng)驗 獲得超15個贊

 var app = new Vue({

  el: "#app",

  data(){

    return {

    opened:[],

    stateGDP: [

        { State: "Rajasthan", "1999-00": "2547", "2000-01": "3679",Id:"23" },

        { State: "Orissa", "1999-00": "38714", "2000-01": "38814",Id:"24" }

      ],

      DistrictGDP: [

        {

          State: "Rajasthan",

          District: "Jaipur",

          "1999-00": "2547",

          "2000-01": "3679",

          Id:"23"

        },

        {

          State: "Rajasthan",

          District: "Jodhpur",

          "1999-00": "2557",

          "2000-01": "3639",

          Id:"23"

        },

        {

          State: "Orissa",

          District: "Bhubaneswar",

          "1999-00": "1983",

          "2000-01": "2068",

          Id:"24"

        },

        {

          State: "Orissa",

          District: "Puri",

          "1999-00": "1923",

          "2000-01": "2008",

          Id:"24"

        }

      ]

      }

    },

  methods:{

    toggle:function(Id) {

    const index = this.opened.indexOf(Id);

    if (index > -1) {

      this.opened.splice(index, 1)

    } else {

      this.opened.push(Id)

    }


 },

    getRows(id) {

      return this.DistrictGDP.filter(district => district.Id === id);

    }

}

})

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js">. 

</script>

<div id="app">

  <div class="table">

    <table class="table-fill">

      <thead>

        <tr>

          <th class="text-center">State/UT</th>

          <th class="text-center">1999-00</th>

          <th class="text-center">2000-01</th>

        </tr>

      </thead>

      <template v-for="row in stateGDP" :class="{ opened: opened.includes(row.Id) }">

        <tr @click="toggle(row.Id)" style="background-color: #D3D3D3">

          <td>{{ row.State }}</td>

          <td>{{ row["1999-00"] }}</td>

          <td>{{ row["2000-01"] }}</td>

        </tr>

        <template

          v-if="opened.includes(row.Id)"

        >

          <thead>

            <tr>

              <th class="text-center">District</th>

              <th class="text-center">1999-00</th>

              <th class="text-center">2000-01</th>

            </tr>

          </thead>

        <tr v-for="(district, index) in getRows(row.Id)">

          <td colspan="1">{{district.District}}</td>

          <td colspan="1">{{district['1999-00']}}</td>

          <td colspan="1">{{district['2000-01']}}</td>

        </tr>

        </template>

      </template>

    </table>

  </div>

</div>

現(xiàn)在的解釋是,為了獲得要在單擊時顯示的行,您正在執(zhí)行一個 v-for 循環(huán),并重新創(chuàng)建標(biāo)頭和整個嵌套表,其次數(shù)與 DistrictGDP 存在時相同,并且具有相同的 ID 與狀態(tài) GDP 相同(在本例中為兩次)。

我刪除了 v-for(整個代碼中的第二個),為了呈現(xiàn)嵌套表行,我添加了一個方法 getRows,此方法基于該行篩選所需的行。Id,這樣,表格就不需要比較地區(qū)GDP中的ID是否與州GDP中的ID相同。

請,如果我不清楚,請告訴我。


查看完整回答
反對 回復(fù) 2022-09-23
  • 1 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號