Javascript 在dojo存储中设置数据以重新提交网格
问题是,我不知道如何更新/重新提交存储、datagrid或此过程中涉及的任何内容(代码有点混乱,但如果对此有疑问,请让我知道) 在旧的实现(工作正常)中,它是一个带有textArea的过滤器,在这个textArea中,可以插入的ID限制为100个,并使用它们创建查询 ID作为参数在请求头(Get)中传递,数据被正确恢复并绘制在网格中 下面是代码的一些部分,以便更好地理解问题 First.jsJavascript 在dojo存储中设置数据以重新提交网格,javascript,dojo,xmlhttprequest,dgrid,Javascript,Dojo,Xmlhttprequest,Dgrid,问题是,我不知道如何更新/重新提交存储、datagrid或此过程中涉及的任何内容(代码有点混乱,但如果对此有疑问,请让我知道) 在旧的实现(工作正常)中,它是一个带有textArea的过滤器,在这个textArea中,可以插入的ID限制为100个,并使用它们创建查询 ID作为参数在请求头(Get)中传递,数据被正确恢复并绘制在网格中 下面是代码的一些部分,以便更好地理解问题 First.js gridLiveView = new LiveViewTable({
gridLiveView = new LiveViewTable({
"storeLink" : 'monitor/store/communications',
'query' : _filterWidgets.getStoredValues(),
'useColumns' : [...]
},
on(selectButton, "click", function(event) {
_filterWidgets.storeValues();
gridLiveView.set('query', _filterWidgets.getStoredValues());
});
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
});
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);
}
LiveViewTable.js
gridLiveView = new LiveViewTable({
"storeLink" : 'monitor/store/communications',
'query' : _filterWidgets.getStoredValues(),
'useColumns' : [...]
},
on(selectButton, "click", function(event) {
_filterWidgets.storeValues();
gridLiveView.set('query', _filterWidgets.getStoredValues());
});
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
});
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);
}
_getStoredValues()返回带有筛选器值的映射
存储和网格是自定义存储,从(dojo/store/JsonRest和dgrid/OnDemandGrid)扩展而来
现在,情况已经改变,限制不是100个,而是20000个ID。因此,请求的头太长,我得到一个错误。这就是为什么要尝试另一种解决方案
在onClickEvent(gridLiveView.set('query',_filterWidgets.getStoredValues());)上没有调用此方法,而是在与Second.js中的构造函数相同的级别上实现并调用了另一个方法,但没有成功
在LiveViewTable.js中添加调用的方法
gridLiveView = new LiveViewTable({
"storeLink" : 'monitor/store/communications',
'query' : _filterWidgets.getStoredValues(),
'useColumns' : [...]
},
on(selectButton, "click", function(event) {
_filterWidgets.storeValues();
gridLiveView.set('query', _filterWidgets.getStoredValues());
});
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
});
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数据具有我希望在表中显示的正确数据。但是我试着在这个.store中设置一个新的store,也在这个.data中,但是网格总是空的。也尝试了此操作。刷新()
所以问题是,我必须如何处理var数据才能在网格中显示它的内容
我尝试过这样的事情(没有成功):
或
您应该通过
grid.set('store',…)
设置新的存储,如中所述。直接重新分配存储
属性并不能让dgrid知道存储实际发生了更改。请确切说明您是如何尝试更新存储或其数据的,因为这很可能是问题所在。编辑,这是我尝试过的事情。我尝试了this.set('store',新内存({data:data}))和this.set('store',new Observable(new Memory({data:data})),但它不起作用。我是否遗漏了什么?假设this
是您的dgrid实例/扩展,应该可以起作用……您可能想尝试将您的案例缩减为起作用的,然后重新构建。