当单击相关行时,我尝试检索存储在 dojo.gridx 表中的数据值。只要第一次调用以下函数,它就可以正常工作,当使用新数据再次调用该函数时,这些数据会正确显示在屏幕上,但当我单击任何行时,检索到的实际数据是属于该行的数据保存第一次调用该函数时加载的数据。获取正确数据的唯一方法是调用 java 脚本重新加载整个 html 页面。作为“dati”加载的数据动态地来自此处未显示的 ajax-js。
HTML reference:
<table data-dojo-type="gridx.Grid" id="userconf" selectable="true" selectionMode="single" singleClickEdit="true" style="width: 936px; position: absolute; z-index: 900; left: 23px; top: 280px; height: 170px;" data-dojo-props="cacheClass: 'gridx/core/model/cache/Async',store:ItemFileWriteStore_11">
<thead>
<tr>
<th field="cf_utente" width="auto" editable="true" type="dojox.grid.cells.Bool">
cf_utente</th>
<th field="sn_contatore" width="auto" editable="true" type="dojox.grid.cells.Bool">
sn_contatore</th>
<th field="sn_serbatoio" width="auto" editable="true" type="dojox.grid.cells.Bool">
sn_serbatoio</th>
<th field="seqnum" width="auto" editable="true" type="dojox.grid.cells.Bool">
seqnum</th>
</tr>
</thead>
</table>
j脚本:
function fillupAnagUsers(dati) {
var grid = dijit.byId('userconf');
var rows = dati.split("\n");
var righe = [];
var data = {items: righe};
var i,j,rw,x;
var lbl = rows[0].split(",");
var newStore = new dojo.data.ItemFileWriteStore({data: data});
for(i=1;i<rows.length-1;i++) {
rw = rows[i].split(",");
x = "{";
for(j=0;j<lbl.length-1;j++) {
x +=lbl[j]+":\""+rw[j]+"\",";
}
x += lbl[j]+":\""+rw[j]+"\"}";
eval('var obj='+x);
data.items.push(obj);
}
grid.setStore(newStore);
var handle = dojo.connect(grid, "onCellClick", grid, function(evt){
var idx = evt.rowIndex;
var data = this.cell(idx, 0).data();
dojo.byId('cfutente').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
data = this.cell(idx, 1).data();
dojo.byId('sncontatore').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
data = this.cell(idx, 2).data();
dojo.byId('snserbatoio').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
data = this.cell(idx, 3).data();
dojo.byId('useqnum').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
dojo.byId('rec').value = dojo.byId('useqnum').value;
});
}
最佳答案
GridX 需要标识符:
var data = {items: righe, identifier: 'myidfield'};
设置存储还不够,还需要清理缓存并强制刷新网格内容:
grid.model.clearCache();
store = new Memory({data: data});
grid.model.setStore(store)
grid.body.refresh()
关于dojo - 从 dojo.gridx 获取行内容它总是显示最初加载的旧数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11688469/