Backbone fetch - "url" 属性 or function must be specified 错误
Backbone fetch - "url" property or function must be specified error
刚接触 Backbone,所以请注意我的无知...
我有一个简单的 GallereyModel:
var GalleryModel = Backbone.Model.extend({
defaults : {
id: "",
width: ""
},
url : ""
});
更新模型时,调用函数galleryModelUpdate
var GalleryView = Backbone.View.extend({
initialize: function () {
this.listenTo(this.model, "change", this.galleryModelUpdate);
},
galleryModelUpdate: function(){
console.log("updated gallery model"+this.model.get("id");
if (this.model.get("url")){
console.log("fetching " + this.model.get("url")); // this line prints with the correct url
this.model.fetch({ // this line gives error
success: function(){
console.log("fetched succesfully!");
}
});
}
}
});
我在调用 fetch 之前在模型上打印 url 的值,所以不确定为什么会抛出 "url" 未定义错误?
非常感谢您的提前帮助
刚接触 Backbone,所以请注意我的无知...
我有一个简单的 GallereyModel:
var GalleryModel = Backbone.Model.extend({
defaults : {
id: "",
width: ""
},
url : ""
});
更新模型时,调用函数galleryModelUpdate
var GalleryView = Backbone.View.extend({
initialize: function () {
this.listenTo(this.model, "change", this.galleryModelUpdate);
},
galleryModelUpdate: function(){
console.log("updated gallery model"+this.model.get("id");
if (this.model.get("url")){
console.log("fetching " + this.model.get("url")); // this line prints with the correct url
this.model.fetch({ // this line gives error
success: function(){
console.log("fetched succesfully!");
}
});
}
}
});
我在调用 fetch 之前在模型上打印 url 的值,所以不确定为什么会抛出 "url" 未定义错误?
非常感谢您的提前帮助