在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.
$data = '({"total":"' . $count . '","results":' . json_encode ( $array ) . '})' ;
This was the response when i deleted the last row, using the line above.
({"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.
$json = json_encode ( $array );
if( $json == 'null' )
{
$json = '[]' ;
}
$data = '({"total":"' . $count . '","results":' . $json . '})' ;
This returns
({"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显示的数据。