0

我有以下 Extjs3 ArrayStore。在其他地方,我正在侦听一个值并在页面的其他地方(商店下方的代码)重新加载带有新数据的商店。我正在寻找一种方法来“重置”或在加载后将存储重新初始化为原始数据..即下一次通过侦听器

商店:

  var applicationVersionStoreOriginalData = [
            <c:set var="firstLoop" value="true"/>
            <c:forEach var="productline" items="${environmentLookup.productlines}">
            <c:forEach var="application" items="${productline.applications}">
            <c:if test="${!firstLoop}">,
            </c:if>
            <c:set var="firstLoop" value="false"/>
            ["<c:out value="${application.recid}"/>","<%=ValueC.PRODUCT_NOT_LISTED%>","<%=ValueC.PRODUCT_NOT_LISTED%>"]
            <c:forEach var="applicationversion" items="${application.applicationversions}">,
            ["<c:out value="${application.recid}"/>","<spring:message text="${applicationversion.applicationversion}" javaScriptEscape="true"/>","<c:out value="${applicationversion.recid}"/>"]
            </c:forEach>
            </c:forEach>
            </c:forEach>
        ];

    var applicationversionStore = new Ext.data.ArrayStore({
        fields: ['applicationId', {name: 'applicationversionName', type: 'string'}, 'applicationversionId'],
        data: applicationVersionStoreOriginalData,
        originalData: applicationVersionStoreOriginalData
    });

数据加载:

function filterApplicationVersionStore(appRecId) {
        console.log('AppRecId =' + appRecId);
        var store = Ext.getCmp("applicationversionCombo").getStore();
        var unlistedData = [[appRecId,"-- My version is not listed here --","-- My version is not listed here --"]];
        var applicationVersionStoreOriginalData = Ext.getCmp('applicationVersionStoreOriginalData')
        var applicationVersionCombo = Ext.getCmp('applicationversionCombo');

        if (!store.originalData) {
        store.originalData = store.getRange();
        }

        if (appRecId == '0309CD56B8CF4245A49E8C201C59AD36') {
            console.log('loading new data');
            store.loadData(unlistedData, false);
            store.reload();
        }
        else {
            console.log('loading old data');
            if (store.originalData) {
            store.loadData(store.originalData, false);
            }
        }
    }

我现在希望能够使用原始数据重新加载商店;那可能吗?

非常感谢!

我在 ExtJs3.4

这是我在控制台中看到的..

passing appRecId to function = AAEBD771130144A3A207F8BDF10B910F 
AppRecId =AAEBD771130144A3A207F8BDF10B910F 
loading old data 

---WORKS (if i disable //store.loadData(store.originalData, false);) -- otherwise the store has dupes and seems to contain mulitples

passing appRecId to function = 0309CD56B8CF4245A49E8C201C59AD36 
AppRecId =0309CD56B8CF4245A49E8C201C59AD36 
loading new data 

--NEW 'EMPTY' DATA IS THERE

passing appRecId to function = 987C7D2D6D194E5196F7598DDC624480 
AppRecId =987C7D2D6D194E5196F7598DDC624480 
loading old data 

--EMPTY!
4

1 回答 1

1

商店不支持开箱即用地恢复被替换的数据……但是您可以自己轻松地实现它。

以下是如何使用您的代码完成此操作:

if (some condition) {
    // save original data before losing it
    if (!store.originalData) {
        store.originalData = store.getRange();
    }

    var data = [
        [appRecId,"-- My version is not listed here --","-- My version is not listed here --"]
    ];
    store.loadData(data, false);
    store.reload();
} else {
    // restore original data
    if (store.originalData) {
        store.loadData(store.originalData);
    }
    // else, that's probably still original data
}

编辑

如何确保它originalData永远存在:

var data = [
    <c:set var="firstLoop" value="true"/>
    <c:forEach var="productline" items="${environmentLookup.productlines}">
        <c:forEach var="application" items="${productline.applications}">
            <c:if test="${!firstLoop}">,</c:if>
            <c:set var="firstLoop" value="false"/>
            ["<c:out value="${application.recid}"/>","<%=ValueC.PRODUCT_NOT_LISTED%>","<%=ValueC.PRODUCT_NOT_LISTED%>"]
            <c:forEach var="applicationversion" items="${application.applicationversions}">,
                ["<c:out value="${application.recid}"/>","<spring:message text="${applicationversion.applicationversion}" javaScriptEscape="true"/>","<c:out value="${applicationversion.recid}"/>"]
            </c:forEach>
        </c:forEach>
    </c:forEach>
];

var applicationversionStore = new Ext.data.ArrayStore({
    fields: ['applicationId', {name: 'applicationversionName', type: 'string'}, 'applicationversionId'],
    data: data,
    originalData: data
});
于 2013-07-24T23:07:36.220 回答