我将amplify.js与Knockout.js结合使用,并希望在本地存储数据。我试过使用以下代码:放大导轨,但它对我不起作用。
我的视图模型
define(['services/datacontext'], function (dataContext) {
var store = amplify.store("offlineData"); // Why is agency undefined after retrieving from the store?!?!?!
var agency = ko.observableArray([]);
var initialized = false;
var save = function (agency) {
return dataContext.saveChanges(agency);
};
var vm = { // This is my view model, my functions are bound to it.
//These are wired up to my agency view
activate: activate,
agency: agency,
title: 'agency',
refresh: refresh, // call refresh function which calls get Agencies
save: save
};
return vm;
function activate() {
if (initialized) {
return;
}
initialized = true;
if (initialized == true) {
amplify.store("offlineData", vm.agency);
}
return refresh();
}
function refresh() {
return dataContext.getAgency(agency);
}
});刷新检索数据后,将此数据保存到本地存储区。所以当我再次请求这一页时。我希望var存储包含这些数据,但它是未定义的。
有人知道如何使用放大吗?
发布于 2013-08-21 11:12:46
amplify.store("offlineData", vm.agency);vm.agency是一个函数,因此您需要调用它来获得它的值。
amplify.store("offlineData", vm.agency());https://stackoverflow.com/questions/18125202
复制相似问题