Jquery 使用getJSON如何处理[]响应?
如果没有可显示的记录,我的getJSON响应如下:Jquery 使用getJSON如何处理[]响应?,jquery,getjson,Jquery,Getjson,如果没有可显示的记录,我的getJSON响应如下: { "items": [], "total_count": 0 } 我如何访问“total_count”来编写如下代码: $.each( data.items, function( key, value ) { if(data.items.length == 0) { $('.list').html(''); $('.list').
{
"items": [],
"total_count": 0
}
我如何访问“total_count”来编写如下代码:
$.each( data.items, function( key, value ) {
if(data.items.length == 0) {
$('.list').html('');
$('.list').html('the ' + address + ' list is empty');
return false;
} else {
// continue to display the returned records
}
data.items.length
不起作用我尝试了==0、==1、>1if(!this["some_returned_item"])
这也不起作用。我真正想要的是,如果(“total_count”==0)做其他事情,做其他事情
有什么想法吗,伙计们?非常感谢 由于数组为空,因此传递给
$的回调函数甚至不会调用每个
(每个项调用一次)。您必须在此回调中执行测试:
if (data.items.length === 0) {
$('.list').html('the ' + address + ' list is empty');
} else {
$.each( data.items, function( key, value ) {
// continue to display the returned records
});
}
无需在此处调用$('.list').html(
两次)。