我正在尝试在单击相关行时检索存储在 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>
脚本:
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;
});
}