Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
Jquery jqGrid不使用新数据刷新_Jquery_Jqgrid - Fatal编程技术网

Jquery jqGrid不使用新数据刷新

Jquery jqGrid不使用新数据刷新,jquery,jqgrid,Jquery,Jqgrid,我通过传入页码n从服务器获取json数据,该页码应为第n个100行。加载一次并按下“下一页”按钮后,它似乎正确地获取了新数据(刷新时,我输出了新数据中的第一个对象),但它不会在我的网格中填充该数据 <div> <button id="refreshJobsButton">Refresh Jobs</button> <button id="nextPageJobsButton">Next page</button>

我通过传入页码n从服务器获取json数据,该页码应为第n个100行。加载一次并按下“下一页”按钮后,它似乎正确地获取了新数据(刷新时,我输出了新数据中的第一个对象),但它不会在我的网格中填充该数据

<div>
    <button id="refreshJobsButton">Refresh Jobs</button>
    <button id="nextPageJobsButton">Next page</button>
    <table id="JobTable"><tr><td/></tr></table>
    <div id="JobPager" class="ui-widget"></div>
</div>
有人能告诉你哪里不对吗?

在你的代码中搜索
$(function(){
。它与
$(document)相同。ready(function(){
),但是你已经将块
$(function(){
包含在
$(document)中。ready(function(){/code>。你应该删除
$(function(){
)(请参见创建jqGrid的位置附近)

$(document).ready(function() {
    var page = 0;
$('#nextPageJobsButton').button({
            icons: {
                primary: "ui-icon ui-icon-arrowrefresh-1-s"
            }
    }).click(function(){
    page = page + 1;
$("#JobTable").jqGrid('GridUnload');
        refreshJob(page);
        });
};
        function refreshJob(page) {
            var $source = "ajax/refreshJob?page=" + page;

        $.ajax({
            url: $source,
            dataType: "json",
            success: populateJobs,
            error: handleAjaxError
        });
    }

        function populateJobs(jobs) {
    k = Object.keys(jobs)[0];
    l = Object.keys(jobs[k])[0];
    alert ("First job in list is " + jobs[k][l]); //Outputs correct job of that page

        $(function() {
            var grid = $('#JobTable');
            $('#JobTable').jqGrid({
                datatype: 'jsonstring',
                editurl: 'ajax/modifyJob',
                mtype: 'POST',
                loadonce: false,
                datastr: jobs,
                height: 600,
                autowidth: true,
                forceFit: true,
                gridview: true,
                viewrecords: true,
                multiselect: true,
                sortable: false,
                toppager: true,
                treeGrid: true,
                treeGridModel: 'adjacency',
                treedatatype: 'POST',
                ExpandColumn: 'Job',
                ExpandColClick: true,
                colNames: [
                    "Id (hidden)",
                    "Job Type (hidden)"
                ],
                colModel: [{
                    name: 'id',
                    index: 'id',
                    editable: true,
                    edittype: 'text',
                    key: true
                }, {
                    name: 'jobType',
                    index: 'jobType',
                    editable: true,
                    edittype: 'text'
                }],
                jsonReader: {
                    repeatitems: false,
                    root: function(obj) {
                        return obj;
                    },
                    page: function() {
                        return 1;
                    },
                    total: function() {
                        return 1;
                    },
                    records: function(obj) {
                        return obj.length;
                    }
                }
            });