我不断收到“filterMessages 不是函数”错误。这是 Backbone View 类 - 不知道为什么它找不到该功能。
这是 Firebug filterMessages 中的错误未定义第 152 行 (filterMessages("all").each(function(message) {
MessageListView = Backbone.View.extend({
defaults : {
filterString : "all"
},
initialize : function() {
this.collection.on("add", function(model) {
var view = new MessageView({model: model});
$("div.cameras").prepend(view.render().el);
});
this.collection.on("remove", function(model) {
var ID = model.id;
$("#message-" + ID).parent("div.message").remove();
});
this.collection.on("reset", function(models) {
$("div.cameras").empty();
filterMessages("all").each(function(message) {
var view = new MessageView({model: message});
$("div.cameras").prepend(view.render().el);
});
});
},
setFilter : function(filterString) {
this.filterString = filterString;
this.collection.reset(this.collection);
},
filterMessages : function(filterString) {
return this.collection.filter(function(model){
if (filterString == "all")
{
return true;
}
else if (filterString == "active")
{
return model.get("ignore") == "0";
}
else if (filterString == "ignore")
{
return model.get("ignore") == "1";
}
else if (filterString == "flag")
{
return model.get("flag") == true;
}
});
}
});