knockout mapping plugin async

时间:2014-01-13 15:53:56

标签: knockout.js knockout-mapping-plugin

我正在使用knockout映射插件将来自微风查询的数据映射到数组。

以下函数每3秒刷新一次数组。从微风查询中接收数据后:

function refreshArray(itemsArray, predicate, fields, entityName, entityKey) {
    if (predicate) {
        return ds.getProjection(fields, entityName, predicate).then(function (data) {
            ko.mapping.fromJS(data.results, {
                create: function (options) {
                    options.data["isSelected"] = ko.observable(false);
                    return ko.mapping.fromJS(options.data, {});
                }
                , key: function (data) {
                    // Bisogna capire come gestirlo nel caso di una chiave composta.
                    return ko.utils.unwrapObservable(data[entityKey[0].name]);
                }
            }, itemsArray);
        })
    }
    else itemsArray([]);
};

使用大数据集导致在映射期间执行小任务(在4K记录上大约3秒)。

你有什么建议吗? (我是否必须使映射异步?我可以使用其他插件,如knockout.viewmodel吗?)

0 个答案:

没有答案
相关问题