我的目标是获取我显示的DataGrid中的所有行,遍历每一行,获取某些项和值,以及更新UI中的字段 . 根据我所读到的内容,最好 grab 数据存储区并进行操作 .

用户正在编辑Dojo数据网格(可编辑列)并单击“保存”按钮以保存更改(RESTService.save()) . 在“保存”按钮过程中,我想循环访问数据存储区 .

我正在使用这个例子:http://xcellerant.net/2013/06/13/dojo-data-grid-21-locking-columns/

这是我的REST服务:

<xp:this.resources>
<xp:dojoModule name="dojo.data.ItemFileWriteStore"></xp:dojoModule></xp:this.resources><xe:restService id="rsVictims" pathInfo="rsVictimsData">
<xe:this.service>
    <xe:viewJsonService defaultColumns="true"
        viewName="InvoiceMPRVictims">
        <xe:this.databaseName><![CDATA[#{javascript:applicationScope.get("appConfig").keywords.appDataStore.join("!!");}]]></xe:this.databaseName>
        <xe:this.keys><![CDATA[#{javascript:viewScope.get("mprKeysValue");}]]></xe:this.keys>
    </xe:viewJsonService>
</xe:this.service>
</xe:restService>

这是“保存”按钮:

<xp:button value="Save Changes" id="victimsSaveButton">
            <xp:eventHandler event="onclick" submit="false">
                <xp:this.script><![CDATA[// Save the changes...
try{
rsVictims.save();

var jsonStore;

// Get the datastore...
jsonStore = new dojo.data.ItemFileWriteStore({url: "invoices_page1_doc.xsp/rsVictimsData"});

    // Cycle through the jsonStore...

}
catch (e) {
alert(e);
}
]]></xp:this.script>
            </xp:eventHandler>
        </xp:button>

我希望得到一些关于如何循环数据存储返回的示例 . 我在这篇参考文献中看到了一些想法,但不确定使用哪一个:http://dojotoolkit.org/reference-guide/1.9/dojo/data/ItemFileWriteStore.html

另外,在抓取数据存储区之前保存REST服务(rsVictims.save();)会给出当前值吗?

谢谢!

--------------编辑1/6/2014 ----------------------

我已更新“保存”按钮以使用此代码:

try {
rsVictims.save();

var item;
var itemStore;
var itemName;
var itemValue;

// Get the datastore...
itemStore = new dojo.data.ItemFileReadStore( {
    url : "invoices_page1_doc.xsp/rsVictimsData"
});

itemName = "month_11";

function failed(error) {
    // Do something with the provided error.
    alert(error);
}

function gotItem(item) {
    if (itemStore.isItem(item)) {
        itemValue = itemStore.getValue(item, itemName);
        alert(itemValue);       
    } else {
        // This should never occur.
        throw new Error("Unable to locate the item with identity [sv]");
    }
}

// Invoke the lookup. This is an async call as it may have to call back to a
// server to get data.
itemStore.fetchItemByIdentity( {
    identity : itemName,
    onItem : gotItem,
    onError : failed
});
} catch (e) {
    alert(e);
}

但是,我没有在gotItem函数中获得任何返回值,并且我没有收到任何错误 .

我可能错过了一些东西 - 任何帮助都会很棒!

谢谢!