3
我想與Backbone.sync()一起使用YDN,但我遇到了«fetchAll»函數的問題。Javascript - BackboneJS - Backbone.sync覆蓋 - YDN - 異步錯誤
對於爲例,我已經由此看來
var UserListView = Backbone.View.extend({
el: ".page",
initialize: function() {
this.users = new UserCollection();
},
render: function() {
var that = this;
this.users.fetch({
success:function(users){
var template = _.template($('#user-list-template').html(), {users : users.models});
that.$el.html(template);
},
error: function(users){
console.log("error");
}
})
}
});
而且在BackboneSync:
switch (method) {
case "read":
resp = model.id ? get(model) : all(model);
break;
case "create":
resp = save(model);
break;
case "update":
resp = save(model);
break;
case "delete":
resp = remove(model);
break;
}
function all(collection) {
db.values("users", null, 10).done(function(records) {
$.each(records, function(index, val) {
collection.add(records);
});
return collection;
});
};
我想你知道我被困。 db.values("users", null, 10).done({...});
是一種異步方法,例如this.users.fetch({})
,在這種情況下,它總是返回錯誤。
你有關於如何處理它的想法嗎?
感謝,
Kai23