【发布时间】:2013-11-19 11:12:06
【问题描述】:
这是我的商店:
Ext.define('NG.store.WhatsNews', {
extend: 'NG.store.AbstractStore',
model: 'NG.model.auxClasses.notifications.WhatsNew',
alias: 'store.whatsnewstore',
autoLoad:true,
buffered: true,
remoteFilter: true,
remoteGroup: true,
remoteSort: true,
pageSize: 50
});
当我向下滚动网格并且缓冲视图尝试加载新记录时,我收到错误“尝试在不存在的上下文中引用节点。”。
这是我在 chrome 开发工具上发现的错误。:
我观察了变量,它拖欠了呼吁:
me.view.bufferRender(newRecords, me.endIndex + 1)
产生一个长度不同的节点数组
recCount = newRecords.length
这会在调用frag.appendChild(newNodes[i]); 时导致错误。
这是一个已知问题吗???
有解决办法吗?
更新
我创建了以下覆盖:
Ext.override(Ext.view.NodeCache, {
/**
* Appends/prepends records depending on direction flag
* @param {Ext.data.Model[]} newRecords Items to append/prepend
* @param {Number} direction `-1' = scroll up, `0` = scroll down.
* @param {Number} removeCount The number of records to remove from the end. if scrolling
* down, rows are removed from the top and the new rows are added at the bottom.
*/
scroll: function (newRecords, direction, removeCount) {
var me = this,
elements = me.elements,
recCount = newRecords.length,
i, el, removeEnd,
newNodes,
nodeContainer = me.view.getNodeContainer(),
frag = document.createDocumentFragment();
// Scrolling up (content moved down - new content needed at top, remove from bottom)
if (direction == -1) {
for (i = (me.endIndex - removeCount) + 1; i <= me.endIndex; i++) {
el = elements[i];
delete elements[i];
el.parentNode.removeChild(el);
}
me.endIndex -= removeCount;
// grab all nodes rendered, not just the data rows
newNodes = me.view.bufferRender(newRecords, me.startIndex -= recCount);
for (i = 0; i < recCount; i++) {
elements[me.startIndex + i] = newNodes[i];
frag.appendChild(newNodes[i]);
}
nodeContainer.insertBefore(frag, nodeContainer.firstChild);
}
// Scrolling down (content moved up - new content needed at bottom, remove from top)
else {
removeEnd = me.startIndex + removeCount;
for (i = me.startIndex; i < removeEnd; i++) {
el = elements[i];
delete elements[i];
el.parentNode.removeChild(el);
}
me.startIndex = i;
// grab all nodes rendered, not just the data rows
newNodes = me.view.bufferRender(newRecords, me.endIndex + 1);
for (i = 0; i < newNodes.length ; i++) {
elements[me.endIndex += 1] = newNodes[i];
frag.appendChild(newNodes[i]);
}
nodeContainer.appendChild(frag);
}
// Keep count consistent.
me.count = me.endIndex - me.startIndex + 1;
}
});
这样可以防止chrome中抛出的错误但是最后一条记录不显示!!!
谁有更好的主意?
【问题讨论】:
标签: javascript extjs extjs4 buffer