[英]Extjs: Delete Row from store-> store.removeAt(RowIndex)
I have a bunch of RowIndexes from a store in my GridPanel. 我在GridPanel中的商店中有一堆RowIndexes。 I want to delete these from my store. 我想从我的商店删除这些。 If I have only one, its no problem, the view from the Grid is refrsehd and the only entry is away. 如果我只有一个,没问题,网格的视图是refrsehd,唯一的条目是。
But when I have more than 0ne, for example 10 RowIndexes and I make this in a loop like here... 但是当我有超过0时,例如10个RowIndexes,我就像这里一样循环...
for(rowIndex in indexes)
{
store.removeAt(indexes[rowIndex]);
}
...only a few entries are deleted from the grid. ...只从网格中删除了几个条目。 I think the loop is too fast? 我觉得循环太快了? I already treid it with a timeout, but doesn't work also. 我已经暂停了它,但是也没有用。 Is there anyone who has an idea? 有没有人有想法? THANKS!!! 谢谢!!!
I would try to remove the rows in reverse order. 我会尝试以相反的顺序删除行。 Have you tried that? 你试过吗? Something like 就像是
var i = indexes.length - 1;
for (; i >= 0; i--){
store.removeAt(indexes[i]);
}
I know an answer has already been accepted, but I thought I'd add that calling Ext.data.Store#removeAt
for each index will fire a datachanged
event each time the method is called. 我知道答案已被接受,但我想我会补充说,每次调用Ext.data.Store#removeAt
为每个索引调用Ext.data.Store#removeAt
都会触发一个datachanged
事件。 If you have a datachanged
listener, you may experience performance issues or unintended behavior. 如果您有datachanged
侦听器,则可能会遇到性能问题或意外行为。 Since removeAt(index)
is just a convenient alias for remove(getAt(index))
you can do this instead. 由于removeAt(index)
只是remove(getAt(index))
一个方便的别名,所以你可以这样做。
function batchRemoveAt(store, indexes) {
var records = Ext.Array.map(indexes, function (index) {
return store.getAt(index);
});
store.remove(records);
}
This will fire a single datachanged
event for the entire remove, as well as the single remove
events for each record removed. 这将为整个删除触发单个datachanged
事件,并为每个删除的记录触发单个remove
事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.