ExtJs ArrayStore(重新加载还是重新启动?)有可能吗?

时间:2013-07-24 22:55:58

标签: javascript extjs extjs3

我有以下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!

1 个答案:

答案 0 :(得分: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
});