我正在使用带有 Knockout.js 的 amplify.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 store 包含这些数据,但它是未定义的。
有谁知道如何使用放大?