我寫了下面的代碼(*)Backbone.model:對象功能(一){返回新N(A)}有沒有方法 '有'
當我試圖運行下面的代碼(** )在我的JS控制檯,
我得到以下結果:
"your attributes are: ", Object // json object taken from the server as I was expecting
Object function (a){return new n(a)} has no method 'has'
爲什麼我得到has no method 'has'
的問題?
-
(**)
require.config({
baseUrl: "/"
});
require(["js/models/task"], function (Model) {
var model = new Model({id: 1});
model.fetch();
console.log(model.attributes);
});
(*)
define([], function() {
var MyModel = Backbone.Model.extend({
initialize: function()
{
this.bind("change", function() {
console.log("this model has been changed")
});
this.bind("error", function (model, error) {
console.log(error);
})
},
urlRoot: "/",
url: function() {
var base = this.urlRoot || (this.collection && this.collection.url) || "/";
if (this.isNew()) return base;
return base + this.id;
},
validate: function (attribute) {
if (typeof attribute === "object") {
console.log("your attributes are: ", attribute);
}
}
});
return MyModel;
});
它只是今天happend給我,將Underscore更新爲最新版本修復程序d it。 – fguillen
是的,這只是一個下劃線版本的問題。 – underscore666