Я пытаюсь сохранить модель, я могу сохранить первую модель в порядке, однако, если я сохраню одну модель, а затем другую сразу после этого, я получаю следующее сообщение об ошибке,Backbone - Uncaught TypeError: Object [object Object] не имеет метода 'call'
Uncaught TypeError: Object [object Object] has no method 'call'
что бы быть причиной этой ошибки?
Моя сохранить код выглядит так,
GroupModalHeaderView.prototype.save = function(e) {
var $this = this;
this.collection = new app.GroupCollection();
if(this.$("#group-name").val() !== "") {
this.collection.add(this.model,{
merge: true
});
}
this.model.save({
name: this.$("#group-name").val(),
async: false,
wait: true
}, {
success: function() {
var GroupList = new app.GroupListView({
model: $this.model,
collection: $this.collection
});
var modal = new app.GroupModalView({
model: $this.model,
collection: $this.collection
});
$this.collection.on("change", GroupList.render(), this);
$this.collection.on("change", modal.render(), this);
//return $this.cancel();
}
});
};
И моя модель код выглядит так,
(function() {
var Group, GroupSearchModel,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Group = (function(_super) {
__extends(Group, _super);
function Group() {
return Group.__super__.constructor.apply(this, arguments);
}
Group.prototype.urlRoot = config.base + "api/group/groups";
Group.prototype.defaults = {
user_id: "",
name: "New Group",
email: "",
url: "",
telephone: "",
mobile: "",
fax: "",
people: ""
};
Group.prototype.idAttribute = "id";
return Group;
})(app.BaseModel);
GroupSearchModel = (function(_super) {
__extends(GroupSearchModel, _super);
function GroupSearchModel() {
return GroupSearchModel.__super__.constructor.apply(this, arguments);
}
return GroupSearchModel;
})(app.BaseModel);
this.app = window.app || {};
this.app.Group = Group;
this.app.GroupSearchModel = GroupSearchModel;
}).call(this);
Я предполагаю, что это что-то делать с .call(this)
в конце моего модель?
на основе коды, вам действительно нужно прочитать эту статью о том, как структурировать взгляды магистральных и модель: http://alexkinnee.com/2013/12/optimal-use-of-backbone-js-model -events-and-mvc-structure/ :) –