【问题标题】:get serial number in reverse order in vue js在vue js中以相反的顺序获取序列号
【发布时间】:2018-10-05 13:58:51
【问题描述】:

下面是迭代列表时显示序列号的代码。 现在由于某些原因我无法对列表进行排序,列表将保持原样。 但我希望以相反的顺序打印序列号。如果数组的大小为 5,我需要 5 4 3 2 1。

<table class="table" border=1 width="650" style="word-wrap:break-word">
         <tr>
          <td colspan="6" class="heading">
            <b>Corrigendum Document Details</b>
          </td>
        </tr>
              <tr>
                <th align="center" style="width:7.5%">Corr.No.</th>
                <th align="center">Corrigendum Title</th>
                <th align="center">Corrigendum Description</th>
                <th align="center">Published Date</th>
                <th align="center">Document Name</th>
                <th align="center">Doc Size(in KB)</th>
              </tr>
              <tr v-for="(corrworkdoc,index) in corrWorkItemDocumentsAndCorrDetailList" i = index>
                <td>{{index+1}}</td>
                <td>{{corrworkdoc.corrigendumTitle}}</td>
                <td>{{corrworkdoc.corrigendumDescription}}</td>
                <td>{{corrworkdoc.publishedDate}}</td>
                <td><a href="#" v-on:click="doDownload(corrworkdoc.fileName)" title="Download" style="color:blue;">{{corrworkdoc.fileName}}</a></td>
                <td>{{corrworkdoc.docSize}}</td>
              </tr>
    </table>

如何以相反的顺序显示序列号。

【问题讨论】:

  • 您只想要索引甚至内容?
  • 你不能创建一个主数组的副本并反转它吗??

标签: javascript html arrays vue.js vuejs2


【解决方案1】:

使用计算属性并反转数组或直接在模板中作为 Saeed.At 示例。同时设置正确的索引值。

computed: {
   reverseDetailedList() {
      return this.corrWorkItemDocumentsAndCorrDetailList.slice().reverse();
   }

在模板中:

<tr v-for="(corrworkdoc,index) in reverseDetailedList" :key="index">
   <td>{{ reverseDetailList.length - index }}</td>
   <td>{{ corrworkdoc.corrigendumTitle}}</td>

【讨论】:

  • (corrWorkItemDocumentsAndCorrDetailList.length) - 索引有效。好主意。现在无需反转原始列表,我们就可以反转序列号。谢谢你
【解决方案2】:

试试这个

<tr v-for="(corrworkdoc,index) in corrWorkItemDocumentsAndCorrDetailList.reverse()" i = index>
            <td>{{index+1}}</td>
            <td>{{corrworkdoc.corrigendumTitle}}</td>
            <td>{{corrworkdoc.corrigendumDescription}}</td>
            <td>{{corrworkdoc.publishedDate}}</td>
            <td><a href="#" v-on:click="doDownload(corrworkdoc.fileName)" title="Download" style="color:blue;">{{corrworkdoc.fileName}}</a></td>
            <td>{{corrworkdoc.docSize}}</td>
          </tr>

【讨论】:

  • 但列表顺序不应只更改序列号,而应以相反的顺序打印。我无法反转列表
猜你喜欢
  • 2021-10-13
  • 2018-06-20
  • 1970-01-01
  • 2015-06-06
  • 2012-03-15
  • 1970-01-01
  • 2015-05-20
  • 2018-06-24
  • 2012-11-29
相关资源
最近更新 更多