主干 - 未捕获类型错误:对象 [对象对象] 没有方法“调用”
Backbone - Uncaught TypeError: Object [object Object] has no method '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)
有关?
你的代码中有很多古怪的地方,但我的第一个猜测是这个错误导致了你当前的问题。绑定事件处理程序时,通常希望引用但不执行处理程序函数。因此,您想要GroupList.render
(不带括号(而不是执行函数的GroupList.render()
(带括号(只是引用它而不执行。
$this.collection.on("change", GroupList.render, this);
$this.collection.on("change", modal.render, this);
//return $this.cancel();
相关文章:
- 从联合js rect对象调用引导模式
- 为什么可以't我用Set对象调用Array.prototype.map
- 从数组(JS)中的对象调用函数
- 在CouchDB Map函数中发出日期时-对日期对象调用的内容
- 'stepUp'对未实现接口HTMLInputElement的对象调用
- 从设置为原型的对象调用属性
- 类型错误:'单击'对未实现接口HTMLElement的对象调用
- 从javascript对象调用函数
- 得到"未捕获的类型错误:未定义的不是函数“;当试图从对象调用get()或set()时
- 子对象调用兄弟姐妹'方法
- 是否可以在函数构造函数中识别哪个对象调用它,并在错误的对象调用时中止创建
- Angularjs:错误:'追加'对未实现接口FormData的对象调用.jQuery.param/ad
- 为什么这个带有对象调用函数的Javascript setInterval在传入回调时不计算内部参数
- 生成自定义对象调用
- 对非对象调用了gulp jscs Object.keys
- JavaScript 从子对象调用父函数
- 对字符串对象调用 .localeCompare 与构造特制的 Intl.Collator 对象之间的性能差异
- 一次将所有对象调用到函数中,返回每个对象的特定计算
- 不能从jquery对象调用的Javascript方法
- 从具有事件侦听器的对象调用函数