【发布时间】:2014-04-22 04:27:43
【问题描述】:
我已经实现了 dgrid。真的很整洁。但是,当我单击行标题进行排序时,除一行之外的所有行都消失了。我要疯了,想弄清楚为什么....
让我们试一试。
DGrid,它是一个基于 dojo 的数据网格,参见 http://dojofoundation.org/packages/dgrid/
当将它与 Javascript 和 HTML 一起使用并连接到 Observable MemStore 时,网格会填充,其中几行非常愉快地显示数据。列是可排序的,即您可以单击行/列标题。但是 - 这就是问题所在 - 当单击这些行/列标题对行进行排序时,除一行之外的所有内容都消失了。
使用内存 (dojo/store/Memory) dGrids 数据存储工作正常 - 即行排序成功。然而,当使用 Observable (dojo/store/Observable) 作为数据存储时,排序会导致行折叠。请看下面的例子。
排序与内存配合得很好:
function populateGrid(Memory, message) {
var featureOne = {
"id": message[0].attributes["id"],
"Col2": message[0].attributes["Col2"],
"Col3": message[0].attributes["Col3"]
}
var featureTwo = {
"id": message[1].attributes["id"],
"Col2": message[1].attributes["Col2"],
"Col3": message[1].attributes["Col3"]
}
var data = [feature1, feature2];
var memStore = new Memory({ data: data });
window.queryRecordsGrid.set("store", memStore);
}
使用 Observable 时出现错误:
var memStore;
function populateGrid(Memory, message) {
var feature = {
"id": message[0].attributes["id"],
"Col2": message[0].attributes["Col2"],
"Col3": message[0].attributes["Col3"]
}
var data = [feature];
if (!window.memStore) {
window.memStore = new Observable(new Memory({ data: data }));
window.grid.set("store", window.memStore);
} else {
window.grid.store.notify(feature, feature.id);
}
}
【问题讨论】:
-
并非如此。它仍然只是一个口头描述。请包括relevant parts of the code 并说明您要完成的工作以及您的结果与预期结果有何不同。包括您收到的任何错误消息。请在How to Ask 好问题和 Jon Skeet 的博客文章Writing the perfect question 上阅读此建议。请特别注意“黄金法则”,但我强烈建议您阅读整篇文章。