问题是我不知道如何更新/重新渲染商店、数据网格或此过程中涉及的任何内容(代码有点困惑,但如果有疑问,请告诉我)
在旧的实现中(可以正常工作),它是一个带有 textArea 的过滤器,在这个 textArea 中,可以插入的 id 限制为 100 个,并且使用它们创建查询。
ID 作为参数在请求 (Get) header 中传递,并且数据已正确恢复并绘制在网格中。
这里是代码的一些部分,可以更好地理解问题。
First.js
gridLiveView = new LiveViewTable({
"storeLink" : 'monitor/store/communications',
'query' : _filterWidgets.getStoredValues(),
'useColumns' : [...]
},
on(selectButton, "click", function(event) {
_filterWidgets.storeValues();
gridLiveView.set('query', _filterWidgets.getStoredValues());
});
LiveViewTable.js
function(...) {
var grid = declare([ SortFormatterGrid (Custom Grid) ], {
refreshStore : null,
cacheStore : null,
constructor : function(args) {
lang.mixin(this, args);
// store definitions
var _jsonStore = new SortFormatterJsonRestStore({
idProperty : 'comId',
target : this.storeLink
});
this.cacheStore = new SortFormatterMemoryStore({
idProperty : 'comId'
});
this.store = new Observable(new Cache(_jsonStore,
this.cacheStore));
this.refreshStore = new SortFormatterJsonRestStore({
idProperty : 'comId',
target : this.storeLink
});
_filterWidgets.getStoredValues() 返回带有过滤器值的 map 。
商店和网格是自定义商店,扩展自(dojo/store/JsonRest 和 dgrid/OnDemandGrid)
现在,情况发生了变化,限制不再是 100 个,而是 20000 个 id。因此,请求的 header 太长,并且出现错误。因此,尝试了另一种解决方案。
不是在 onClickEvent (gridLiveView.set('query', _filterWidgets.getStoredValues());) 上调用此方法,而是在与 Second.js 中的构造函数相同的级别实现和调用另一个方法,但没有成功。
LiveViewTable.js 中调用的方法,Addition
update : function(queryMap) {
var url = 'monitor/store/communications';
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", url, false);
xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.send(JSON.stringify(queryMap));
var data = JSON.parse(xmlhttp.responseText);
}
该var data具有我想要在表格中显示的正确数据。但我尝试在 this.store 中设置一个新的 Store,也在 this.data 中设置,但网格始终为空。也尝试过 this.refresh()。
所以问题是,我必须如何处理var data才能在网格中显示其内容?
我尝试过这样的事情(没有成功):
this.data = data;
或
this.store = new Observable(new Memory({data: data}));
最佳答案
您应该通过 grid.set('store', ...)
设置新商店,如 documentation 中所述。 。直接重新分配 store
属性并不能让 dgrid 知道 store 实际发生了变化。
关于javascript - 在 dojo Store 中设置数据以重新渲染网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27103184/