当 load
存储事件如下时,我将新行(记录)添加到网格中
var dt = new Date();
var rec = new store.recordType({ }, "new" + dt.format('U'));
rec.set('ID', '1');
store.insert(store.getCount(), rec);
store.insert(store.getCount()+1, rec);
grid.getView().refresh();
但我无法将 2 个空的最后一行添加到网格中。我怎样才能在网格中添加 2 个空行。
注意:如果没有这一行,只在网格中添加一行 store.insert(store.getCount()+1, rec);
但是当我添加 store.insert(store .getCount()+1, rec);
进入我的错误代码。
最佳答案
首先是关于您的代码片段的一些评论:
您正在创建 ID 值为 "new"+ dt.format('U')
的新记录,并在下一行中将此 ID 设置为 1?您应该使用适当(且唯一)的 ID 创建记录。否则您可以覆盖现有记录。
现在你的问题:
您正在添加具有相同 ID 的记录两次。所以对于商店来说只有一条记录。要么根本不分配 ID 值并让 ExtJS 处理它,要么确保每个实例都获得它自己的唯一 ID。并且每次都创建一个新实例!
你需要做这样的事情:
var rec1 = new store.recordType({}, 1); // remove the 1 with your own unique ID value
var rec2 = new store.recordType({}, 2); // remove the 2 with your own unique ID value
store.insert(store.getCount()-1, [rec1,rec2]);
关于extjs - 如何最后添加两行网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20233698/