jqGrid的getDataIDs()返回空数组,即使网格中有数据 //main.php中的JavaScript延迟加载 var lista=jQuery(“#list”).getDataIDs(); console.log(lista); ------------------------------- //getdata.php $responce=新的stdClass; $responce->page=$page; $response->total=$total\u页面; $responce->records=$count; $i=0; 而($row=mysql\u fetch\u array($result,mysql\u ASSOC)){ $response->rows[$i]['id']=$row['slidescol']; $response->rows[$i]['cell']=数组($row['torder'],$row['title'],$row['iconpath'],$row['bannerurl'],$row['summary'],$row['headerstitle'],$row['backurl'],$row['forwardurl'],$row['thisrurl'],$row['slidescol']); $i++; } fclose($handle); echo json_编码($response);

jqGrid的getDataIDs()返回空数组,即使网格中有数据 //main.php中的JavaScript延迟加载 var lista=jQuery(“#list”).getDataIDs(); console.log(lista); ------------------------------- //getdata.php $responce=新的stdClass; $responce->page=$page; $response->total=$total\u页面; $responce->records=$count; $i=0; 而($row=mysql\u fetch\u array($result,mysql\u ASSOC)){ $response->rows[$i]['id']=$row['slidescol']; $response->rows[$i]['cell']=数组($row['torder'],$row['title'],$row['iconpath'],$row['bannerurl'],$row['summary'],$row['headerstitle'],$row['backurl'],$row['forwardurl'],$row['thisrurl'],$row['slidescol']); $i++; } fclose($handle); echo json_编码($response);,jqgrid,Jqgrid,我试图确定为什么我的控制台.log返回一个空白数组或空集,即使网格中有四行 提前感谢…您提出的代码没有准确地显示您的代码在JavaScript中被调用的方法getDataIDs。我想你叫错地方了。最初,页面上的一个位置是空的,然后您应该针对$(“#列表”).jqGrid({/*选项*/})创建网格。只能在创建的网格上使用getdataid,而不能在空的元素上使用。通常在loadComplete回调中使用getdataid,因为在这里可以确保网格已创建,并且数据已填充到jqGrid的主体中。对我有

我试图确定为什么我的
控制台.log
返回一个空白数组或空集,即使网格中有四行


提前感谢…

您提出的代码没有准确地显示您的代码在JavaScript中被调用的方法
getDataIDs
。我想你叫错地方了。最初,页面上的一个位置是空的
,然后您应该针对
$(“#列表”).jqGrid({/*选项*/})创建网格
。只能在创建的网格上使用
getdataid
,而不能在空的
元素上使用。通常在
loadComplete
回调中使用
getdataid
,因为在这里可以确保网格已创建,并且数据已填充到jqGrid的主体中。

对我有效的是:

...

loadComplete: function() {

    var ids = $(this).jqGrid('getDataIDs');

    // i'm expanding all the sub grids here, but can do anything with the array
    var len = ids.length;
    for (var i=0; i < len; i++) {
        $(this).jqGrid('expandSubGridRow', ids[i]);
    }

}
。。。
loadComplete:function(){
var id=$(this).jqGrid('getdataid');
//我在这里扩展所有的子网格,但是可以用数组做任何事情
var len=ids.length;
对于(变量i=0;i
对于您的回复,我必须深表感谢。在loadcomplete.Oleg中,现在一切都工作得更好了,我在loadcomplete中调用了getdataid,它返回了一个空数组。有什么好处?网格中充满了数据,所以它被加载了……@sarsnake:你应该发布更完整的描述,说明你在做什么,需要做什么。我的意思是需要查看JavaScript代码和用于输入的测试数据。此外,很少需要使用
getdataid
。在大多数情况下,人们尝试使用
getdataid
而不是更有效地使用jqGrid的其他可能性,如
cellattr
rowttr
beforeselectionrow
beforeProcessing
等等。因此,最好描述您试图解决的问题,而不仅仅是理解为什么
getDataIDs
的工作方式与您期望的不一样。