1

我想根据提供的参数将 JSONStore 加载到适配器映射加载函数。让我更好地解释一下。

JSONStore 初始化是这样的:

collections[EMPLOYEE_COLLECTION_NAME] = {

    searchFields : {ENAME: 'string', EMPNO:'integer'},

    //-- Start optional adapter metadata
    adapter : {
        name: 'EmployeesDB',
        add: 'addEmployee',
        remove: 'deleteEmployee',
        replace: 'updateEmployee',
        load: {
            procedure: 'getEmployee',
            params: [region],
            key: 'resultSet'
        }
    }
    //-- End optional adapter metadata
};


//Initialize the people collection
WL.JSONStore.init(collections, options)

正如您在上面的代码中看到的那样,即使在将参数区域传递给适配器集合 init 之后,它是否应该在我的应用程序生命周期中发生变化,所以有时区域假设是 SOUTH,其他区域是 NORTH 等等.

我意识到,即使我在创建存储后更改了此值,适配器 getEmployee 中的映射加载函数(见下文)始终获取初始化 jsonstore 时包含的区域值,无论我稍后更改区域变量值。看起来适配器绑定 conf 在创建集合时得到,并且从不更改它

function getEmployee(data) {
    WL.Logger.info('Show param:'+data); 
    return WL.Server.invokeSQLStatement({
        preparedStatement : selectStatement,
        parameters : []
    });
}

有没有办法将参数传递给 Jsonstore 加载函数,该函数在存储初始化后可以更改?

我想避免关闭并再次初始化集合以节省时间和资源。

顺便说一句,我真正需要的是根据绑定到集合的适配器参数对从数据库加载的内容具有灵活性。

4

1 回答 1

4

Try something like:

WL.JSONStore.get(EMPLOYEE_COLLECTION_NAME).adapter.load.params = ['...']

Before calling WL.JSONStore.get(EMPLOYEE_COLLECTION_NAME).load().

If you want more flexibility, you can always call WL.Client.invokeProcedure and inside the onSuccess callback you can call: WL.JSONStore.get(EMPLOYEE_COLLECTION_NAME).add(['...'], {push: false}). The push: false section will make sure JSONStore understands that the data added is up-to-date with the data on the backend. This means it won't show those documents when you call: WL.JSONStore.get(EMPLOYEE_COLLECTION_NAME).getPushRequired() or WL.JSONStore.get(EMPLOYEE_COLLECTION_NAME).push().

于 2013-11-22T20:33:18.790 回答