1

I'm wondering if Amplify can easily handle big data model with lots of nested knockout observable objects. The goal is to save and restore current state of the data (view) model after page refresh.

From few examples seems that every observable needs to be extended to use local store. Probably that can be applied globaly, but I'm not sure how will the nested observable objects behave. (ie. viewModel has many observable variables and each of them holds json objects with more observable variables etc.). Is it possible to save the state of the viewModel so that after page refresh all nested observables are restored in a proper way? (Another problem could be performance as it has to be used on the mobile devices)

Does anyone has any experience with these kind of issues?

4

1 回答 1

1

这是可以做到的,我正在这样做。尽管我已将其拆分为单独的模块来处理我的 ajax 调用和缓存。

需要注意的一点是,如果您使用 observables 存储整个淘汰视图模型,则在将其取回时,将不会恢复数据。这是因为你的 observables 是函数而不是数据本身。

为此,您必须将您的可观察视图模型转换为正确的 Javascript 对象(如果使用映射插件,则为 ko.toJS 或 ko.mapping.toJS),然后存储它。当您检索数据时,您必须通过您的视图模型将其发送以重新创建可观察对象。

这并不像你想象的那么昂贵。使用映射插件很容易做到这一点。但是,如果您的阵列中有大量数据,那么您应该重新考虑获取如此多的数据,尤其是对于移动设备。

于 2013-03-07T20:57:46.403 回答