【发布时间】:2014-02-08 03:15:50
【问题描述】:
非常基本的问题,但我似乎无法弄清楚为什么我无法将方法绑定到集合上的重置事件。
HealthcheckList = Backbone.Collection.extend({
model: Healthcheck,
url: "/corsettiServices/rest/healthcheck/sort",
initialize: function() {
_.bindAll(this, "fetchSuccess", "addAll");
console.log("Initializing view");
this.on('reset', addAll);
this.fetch({data: {type:'all'}, processData:true, success: this.fetchSuccess, reset: true});
},
addAll: function(m, options) {
alert("adding");
},
fetchSuccess: function(m, response) {
alert("success");
console.log(m);
m.each(function(h) {
if (h.get("start")!=null) {
$('#statusTable > tbody:last').append('<tr><td>' + h.get("start") + '</td><td>' + h.get("type") + '</td><td>' + h.get("status") + '</td></tr>');
}
})
}
})
这会引发错误:未捕获的 ReferenceError: addAll is not defined。删除与“重置”事件的绑定使得数据获取和代码工作,但我想在每次重置集合时进行更多处理。关于如何在主干集合中定义函数,我缺少什么?
【问题讨论】: