如何使用ng-repeat在AngularJS中自动调整行数

时间:2022-11-16 20:35:07

I am very new to AngularJS. Please forgive if the question is too simple. I have a list which is displayed with ng-repeat with AngularJS. I am using bootstrap pager for paging which selects only 10 records at a time .

我是AngularJS的新手。如果问题太简单,请原谅。我有一个与AngularJS一起使用ng-repeat显示的列表。我正在使用bootstrap寻呼机进行寻呼,一次只能选择10条记录。

var start =0;
var end = 10;
results.slice(start, end);

I want to Autonumber the rows.

我想自动编号行。

This is what i tried.

这是我试过的。

  1. Used $index with ng-repeat .(This works good ,but the index gets repeated in second page)

    使用$ index和ng-repeat。(这很好,但索引在第二页重复)

  2. used

{{sequenceId + 1}} (all numbers show 1)

{{sequenceId + 1}}(所有数字显示1)

I want the numbers to be showed in the table when the table loads.

我想要在表加载时在表中显示数字。

2 个解决方案

#1


0  

  • The standard practice in pagination is to send the last index as part of the request and respond with the next index. So you can pass $index to your API and get it to respond with $index +1
  • 分页的标准做法是将最后一个索引作为请求的一部分发送,并使用下一个索引进行响应。因此,您可以将$ index传递给您的API并使其以$ index +1响应

  • The other option is to store the index in some place, and use a filter like so:

    另一种选择是将索引存储在某个地方,并使用如下过滤器:

    app.filter('startFrom', function() { return function(input, start) { if(input) { start = +start; //parse to int return input.slice(start); } return []; } });

    app.filter('startFrom',function(){return function(input,start){if(input){start = + start; // parse to int return input.slice(start);} return [];}} );

    {{item.Name}}

  • Another option is (assuming that the entire set is available to you) to just add an index to your original data set. Add a continuous index as one of the keys in the array and display that list.
  • 另一个选项是(假设您可以使用整个集合)只是为原始数据集添加索引。添加连续索引作为数组中的一个键并显示该列表。

#2


0  

What about something simple like

简单的事情怎么样?

$index - start + 1

#1


0  

  • The standard practice in pagination is to send the last index as part of the request and respond with the next index. So you can pass $index to your API and get it to respond with $index +1
  • 分页的标准做法是将最后一个索引作为请求的一部分发送,并使用下一个索引进行响应。因此,您可以将$ index传递给您的API并使其以$ index +1响应

  • The other option is to store the index in some place, and use a filter like so:

    另一种选择是将索引存储在某个地方,并使用如下过滤器:

    app.filter('startFrom', function() { return function(input, start) { if(input) { start = +start; //parse to int return input.slice(start); } return []; } });

    app.filter('startFrom',function(){return function(input,start){if(input){start = + start; // parse to int return input.slice(start);} return [];}} );

    {{item.Name}}

  • Another option is (assuming that the entire set is available to you) to just add an index to your original data set. Add a continuous index as one of the keys in the array and display that list.
  • 另一个选项是(假设您可以使用整个集合)只是为原始数据集添加索引。添加连续索引作为数组中的一个键并显示该列表。

#2


0  

What about something simple like

简单的事情怎么样?

$index - start + 1