Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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 AddRowData rowId的值错误_Jquery_Jqgrid_Rowid - Fatal编程技术网

Jquery jqGrid AddRowData rowId的值错误

Jquery jqGrid AddRowData rowId的值错误,jquery,jqgrid,rowid,Jquery,Jqgrid,Rowid,如果我将本地数据(一行)添加到现有jqgrid,则$.jgrid.randId()自动生成的值似乎是错误的。我需要新的行id以进行进一步操作 var mydata = [ {id: '12', thingy: "abc"}, {id: '34', thingy:"def"}, {id: '56', thingy: 'ghi'} ]; $("#grid").jqGrid({ data: mydata , datatype: 'local', g

如果我将本地数据(一行)添加到现有jqgrid,则
$.jgrid.randId()
自动生成的值似乎是错误的。我需要新的行id以进行进一步操作

var mydata = [
    {id: '12', thingy: "abc"}, 
    {id: '34', thingy:"def"}, 
    {id: '56', thingy: 'ghi'}
];

$("#grid").jqGrid({
    data: mydata ,
    datatype: 'local',
    gridview: true,
    height: 'auto',
    autoencode: true,
    rowNum: 3,
    colModel: [{
        name: 'id',
        width: 60,
    },{
        name: 'thingy',
        width: 90,
    }],
    caption: "Stack Overflow Example",
    ondblClickRow: function(rowid) {
        console.log(rowid);  // print current row id
    }
});

$('#UpdateGridButton').click(function(){
    var p = $('#grid').getGridParam();
    console.log("found gridParamData:", p.data);
    if (p.data){
        var newData = [
            {id: '78', thingy: "jkl"}
        ];
        var rowId = $.jgrid.randId(); // new row ID
        $("#grid").jqGrid('addRowData', rowId, newData);
        console.log(rowId); // print new row id
    }    
});
查看此小提琴和控制台输出(2次单击该行):

您可以看到,如果您添加一个新行,行id是“jqg1”,但实际上它插入了一个带有“jqg2”的行(使用firebug检查,如果双击该行,请参阅控制台输出)

有没有办法解决这个问题?还是一只虫子

正如我在这个问题中看到的,我认为函数是错误的,它应该是预增量的,而不是
$.jgrid.guid++

有什么想法吗

更新:

我最终使用了

var rowId = $.jgrid.uidPref + (++$.jgrid.guid);

但是,如果有更好的解决方案/想法,我们将不胜感激。

在阅读源代码并对照文档进行检查后,这不是一个bug

必须添加一行作为对象,然后才能指定rowId。如果将数据添加为对象数组,“rowid应包含数据对象的名称,该名称应作为行的id”(addRowData)

更新了小提琴&它正在工作:

    ...
    var newData = {id: '78', thingy: "jkl"};
    ...