从dojo.gridx获取行内容它始终显示最初加载的旧数据

时间:2012-07-27 13:13:42

标签: dojo dojo.gridx

我正在尝试检索存储在dojo.gridx表中的数据值,因为单击了相关的行。只要第一次调用以下函数时,它工作正常,当用新数据再次调用该函数时,那些数据在屏幕上正确显示,但是当我点击任何行时,检索到的实际数据是属于该行的那些在第一次调用函数时保存数据。获取正确数据的唯一方法是重新加载调用java脚本的整个html页面。以“dati”形式加载的数据来自此处未显示的ajax-j动态。

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>

的JScript:

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;


});

 }

1 个答案:

答案 0 :(得分:4)

GridX需要标识符:

var data = {items: righe, identifier: 'myidfield'};

设置商店是不够的,您还需要清理缓存并强制刷新网格内容:

            grid.model.clearCache();
            store = new Memory({data: data});
            grid.model.setStore(store)
            grid.body.refresh()