Grid - last row not removed when deleted even though reload

 

在spring+struts2+Ext3.2.1的应用中,发现在grid 只有一条记录时,作删除,实际已经删除,但在grid依然存在,查一了一下资料,里面提到

(reffer http://www.extjs.com/forum/showthread.php?76865-Grid-last-row-not-removed-when-deleted-even-though-reload&p=370095)

I've had the same problem. Maybe this helps you.

The following line, in my php script, generated the JSON.

PHP Code:
$data  '({"total":"'  $count  '","results":'  json_encode ( $array ) .  '})'

This was the response when i deleted the last row, using the line above.

Code:
({"total":"0","results":null
})

json_encode returned null (string) and caused the problem.

To solve this, I had to replace null with two empty brackets.

PHP Code:
$json  json_encode ( $array );            
if(
$json  ==  'null' )
{
    
$json  '[]' ;
}
$data  '({"total":"'  $count  '","results":'  $json  '})'

This returns

Code:
({"total":"0","results":[]})

and the grid is refreshed properly.

 

由于使用List<Bean> results 作为对象集合返回,如果没有记录时返回的是null,这对 Ext.data.JsonReade解析应该有点问题,它所解析的空集合应该是{},所以在action端对 results进行判读处理,如果没有数据,则 List<Bean> results = new ArrayList<Bean>();

在页面调用 grid.getStore().reload(),自然会清掉最后一条在grid显示的数据。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值