Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度材质分页下一页功能_Javascript_Angularjs_Json_Pagination - Fatal编程技术网

Javascript 角度材质分页下一页功能

Javascript 角度材质分页下一页功能,javascript,angularjs,json,pagination,Javascript,Angularjs,Json,Pagination,我按照本教程学习如何进行分页 我将一个json、myData和一些项目放在一起,看看它们是如何工作的。因为我是一名初级程序员,我被阻止进入gotoPage() 在我的页面中,我更改了: ctrl.total = ctrl.myData.length; ctrl.currentPage = 1; ctrl.step = 6; ctrl.gotoPage = function() { if(ctrl.total) { for(var i=0; i < ctrl.total;

我按照本教程学习如何进行分页

我将一个json、myData和一些项目放在一起,看看它们是如何工作的。因为我是一名初级程序员,我被阻止进入gotoPage()

在我的页面中,我更改了:

ctrl.total = ctrl.myData.length;
ctrl.currentPage = 1;
ctrl.step = 6;

ctrl.gotoPage = function() {
  if(ctrl.total) {
     for(var i=0; i < ctrl.total; i++) {
            //   
      }
  }
};
ctrl.total=ctrl.myData.length;
ctrl.currentPage=1;
ctrl.step=6;
ctrl.gotoPage=函数(){
如果(ctrl.total){
对于(变量i=0;i
但我不知道该在这个函数中放些什么来显示我的json,比如说每页10个条目。 您可以在演示中看到这些道具和方法


有人能告诉你怎么做吗?

你需要计算起始数量,然后迭代,直到达到该页面的最大值

ctrl.total = ctrl.myData.length; //the total items in your set
ctrl.currentPage = 1; 
ctrl.step = 6; //page size? this could be 10 if you want
ctrl.numpages = ctrl.total/ctrl.step;  //the total number of items partitioned by page size. convert this to a whole number (the ceiling)
 //go to page function here receives the indexes for that page, is that ok?
ctrl.gotoPage = function(Page) { //i modified this to take the page number as an argument
  if(Page<= ctrl.numpages && Page>0) //we need to check that the page is valid
  {
     var startpos = ((Page-1)*(ctrl.step))+1; //this is virtually a skip amount. If its the first page, i = 0, otherwise we start with an increment of the page size. If its the second page, we skip the first 6 results
     for(var i=startpos; i < startpos+ctrl.step; i++) {
            if(i == ctrl.total) //if its the last page we cut it off early
              break;   
      }
  }
};
ctrl.total=ctrl.myData.length//集合中的项目总数
ctrl.currentPage=1;
ctrl.step=6//页面大小?如果你愿意,这可能是10
ctrl.numpages=ctrl.total/ctrl.step//按页面大小分区的项目总数。将其转换为整数(上限)
//go to page函数在这里接收该页的索引,可以吗?
ctrl.gotoPage=function(Page){//我修改了它,将页码作为参数
if(Page0)//我们需要检查页面是否有效
{
var startpos=((第1页)*(ctrl.step))+1;//这实际上是一个跳过量。如果是第一页,则i=0,否则我们从页面大小的增量开始。如果是第二页,则跳过前6个结果
对于(var i=startpos;i
在我的页面中,我使用此指令
请告诉我从哪里获取$ctrl.gotoPage()的页面参数?我的意思是这个参数应该是什么?我假设“$ctrl.currentPage”。因此,您的下一个页面将是$ctrl.gotoPage($ctrl.currentPage+1),但我对您到底想做什么感到有点困惑。上面的代码是你想要的吗?我的朋友,我构建了一个组件1.5 angular版本,我在我的组件html页面中使用了这个教程和这个指令。代码没有问题,但使用此
当前页面=“$ctrl.currentPage”
,在控制台
页面中,inside js显示我单击的页面,但页面中的项目相同。