我想覆盖模型和集合中的fetch方法,以便在没有网络连接时从localstorage中获取数据.
这是集合中的fetch函数
fetch:function(){
if(online){
return Backbone.Collection.prototype.fetch.call(this) ;
}else{
// return Backbone.Collection.fetch event - with data from localstorage
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里面临两个问题
a.成功或错误功能未执行
this.collection.fetch({
success: function(data){ ... },
error: function(){ ... }
});
Run Code Online (Sandbox Code Playgroud)
湾 如果没有连接,如何将数据设置为集合,以便我可以在成功函数中访问它
我用自耕农创建了一个角度应用程序,当我执行grunt命令时出现以下错误
Running "karma:unit" (karma) task
WARN [config]: JASMINE is not supported anymore.
Please use `frameworks = ["jasmine"];` instead.
WARN [config]: JASMINE_ADAPTER is not supported anymore.
Please use `frameworks = ["jasmine"];` instead.
WARN [config]: LOG_INFO is not supported anymore.
Please use `karma.LOG_INFO` instead.
ERROR [config]: Config file must export a function!
module.exports = function(config) {
config.set({
// your config
});
};
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
我试图从$http.then函数返回数据:
if(navigator.onLine){
$http({
method:'GET',
url:url,
}).success(function(data, status){
localStorage.setItem('abc', JSON.stringify(data));
}).then(function(){
return JSON.parse(localStorage.getItem('abc'));
});
}else{
return JSON.parse(localStorage.getItem('abc'));
}
Run Code Online (Sandbox Code Playgroud)
我能够从else块中获取Json数据,但从函数中获取null值then.
这个功能在服务中.