Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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 HTML客户端分页-无法获取动态添加的数据_Javascript_Pagination_Pug - Fatal编程技术网

Javascript HTML客户端分页-无法获取动态添加的数据

Javascript HTML客户端分页-无法获取动态添加的数据,javascript,pagination,pug,Javascript,Pagination,Pug,所以我使用了一个javascript分页,它非常有效。。除了尝试加载动态添加的数据时(从getJSON)。问题是,它正在检查表,但没有找到任何结果,因为它被注入到innerHTML中,我猜不是“硬编码”的 这是javascript script(type='text/javascript') pager = new Pager('results', 3); pager.init(); pager.showPageNav('pager', 'pageNavP

所以我使用了一个javascript分页,它非常有效。。除了尝试加载动态添加的数据时(从getJSON)。问题是,它正在检查表,但没有找到任何结果,因为它被注入到innerHTML中,我猜不是“硬编码”的

这是javascript

script(type='text/javascript')    
    pager = new Pager('results', 3);
      pager.init();
      pager.showPageNav('pager', 'pageNavPosition');
      pager.showPage(1);   
有人知道我能做些什么来解决这个问题吗?我已经尝试使用一些合适的datagrid,但我无法让它们与我的应用程序一起工作

$.getJSON( '/getlocations', function( data ) {
        userListData = data;

        // For each item in our JSON, add a table row and cells to the content string
        $.each(data, function(){
            tableContent += '<tr>';
            tableContent += '<td><a href="#" class="linkshowuser" rel="' + this.name + '" title="Show Details">' + this.name + '</a></td>';
            tableContent += '<td>' + this.information + '</td>';
            tableContent += '<td>' + this.lat + '</td>';
            tableContent += '<td>' + this.lon + '</td>';
            tableContent += '<td><button onclick="viewLocationOnMap()">View on map</button></td>';
            tableContent += '<td>In Progress</button></td>';
            tableContent += '<td><a href="#" class="linkdeleteitem" rel="' + this._id + '">delete</a></td>';
            tableContent += '</tr>';
        });

        // Inject the whole content string into our existing HTML table
        $('#userList table tbody').html(tableContent);
$.getJSON('/getlocations',函数(数据){
userListData=数据;
//对于JSON中的每个项目,向内容字符串添加一个表行和单元格
$.each(数据,函数(){
tableContent+='';
tableContent+='';
tableContent+=''+此信息+'';
tableContent+=''+this.lat+'';
tableContent+=''+this.lon+'';
tableContent+=“在地图上查看”;
tableContent+=‘进行中’;
tableContent+='';
tableContent+='';
});
//将整个内容字符串注入到现有的HTML表中
$('#userList table tbody').html(tableContent);

谢谢

我不太确定您的
HTML是什么样子,我注意到如果我尝试使用空HTML表(即没有行)初始化分页,浏览器控制台将抛出一个错误:

Uncaught TypeError: Cannot set property 'className' of null
paging.js
似乎依赖于这样一个事实,即
行存在,并且使用特定的CSS类设置样式,即定义了
.pg normal
.pgselected
。无论如何,我通过以下方法使代码正常工作:

  • HTML附加在之后实例化分页,并且
  • $('#userList table tbody').html(tableContent);
    替换为
    $('#result').append(tableContent);
    ,因为
    result
    是初始化分页时使用的表的ID
  • 请查看下面的堆栈片段或以下内容:
    /***Javascript***/
    //对于JSON中的每个项目,向内容字符串添加一个表行和单元格
    风险值数据=[
    {id:1,名称:'cell1',信息:'First Row'},
    {id:2,名称:'cell2',信息:'Second Row'},
    {id:3,名称:'cell3',信息:'Third Row'},
    {id:4,名称:'cell4',信息:'4th Row'},
    {id:5,名称:'cell5',信息:'Fifth Row'},
    {id:6,名称:'cell6',信息:'Sixth Row'},
    {id:7,名称:'cell7',信息:'Seventh Row'},
    {id:8,名称:'cell8',信息:'Otherth Row'},
    {id:9,名称:'cell9',信息:'Nineth Row'},
    ];
    var tableContent=“”;
    $.each(数据,函数(){
    tableContent+='';
    tableContent+='';
    tableContent+=“在地图上查看”;
    tableContent+=‘进行中’;
    tableContent+='';
    tableContent+='';
    });
    //将整个内容字符串注入到现有的HTML表中
    $(“#结果”)。追加(tableContent);
    //数据可用后实例化分页
    寻呼机=新寻呼机(“结果”,3);
    pager.init();
    pager.showPageNav('pager','pageNavPosition');
    寻呼机显示页(1);
    //分页对象代码。
    功能页(表名、项目页){
    this.tableName=tableName;
    this.itemsPerPage=itemsPerPage;
    this.currentPage=1;
    此参数为0;
    this.inited=false;
    this.showRecords=函数(从,到){
    var rows=document.getElementById(tableName).rows;
    //我从1开始跳过表格标题行
    对于(变量i=1;i到)行[i].style.display='none';
    else行[i].style.display='';
    }
    }
    this.showPage=函数(页码){
    如果(!this.inited){
    警报(“未初始化”);
    返回;
    }
    var oldPageAnchor=document.getElementById('pg'+this.currentPage);
    oldPageAnchor.className='pg normal';
    this.currentPage=页码;
    var newPageAnchor=document.getElementById('pg'+this.currentPage);
    newPageAnchor.className='pg selected';
    变量from=(页码-1)*itemsPerPage+1;
    var to=from+itemsPerPage-1;
    此。showRecords(从,到);
    }
    this.prev=函数(){
    如果(this.currentPage>1)this.showPage(this.currentPage-1);
    }
    this.next=函数(){
    如果(this.currentPage对于(var page=1;page不确定有什么问题。但我有一些建议。1.不要将双引号括在单引号中,如果有,请尝试转义它们。2.我看不出在哪里声明了
    tableContent
    变量。您必须在
    getJson
    函数中声明它,然后在
    each
    循环中使用它,以便级联工作正常。)ne.3.只需添加一行文本即可进行调试,并查看它的外观。4.
    每个
    都接受
    索引
    作为函数参数,因此在迭代时使用值而不是
    。嗨,好的,谢谢,我会确保双引号。2.这一切都很好,我已经在上面声明过。t没有问题他连接,表格显示完美等等,这就是PageNation哇,太棒了,我在我附加表格的地方直接添加了分页代码,它拾取页面等等!只要一个简单的问题,每当我按下Prev或Next,我就会收到一个“onclick”错误,-uncaught TypeErro:undei