我有两套备用藏书。 我想对重启事件负责。 当这次事件发生时,我要提一下第二次收缴行动,例如:
App.collections.movies.bind("reset", App.collections.theaters.fetch);
第二只字不提火。 然而,如果我通过匿名职能,打电话给殴打者。 fetch, 它没有问题:
App.collections.movies.bind("reset", function () { App.collections.theaters.fetch(); });
为什么会发生这种情况?
这里,我的全面法典。 我不想展示任何模式或收集,因为它有许多法典,但请允许我知道,你是否认为这个问题的根源:
var App = {
init: function () {
App.collections.theaters = new App.Theaters();
App.collections.movies = new App.Movies();
App.events.bind();
App.events.fetch();
},
events: {
bind: function () {
App.collections.theaters.bind("reset", App.theaterManager.assign);
App.collections.movies.bind("reset", function () { App.collections.theaters.fetch(); });
},
fetch: function () {
App.collections.movies.fetch();
}
},
collections: {},
views: {},
theaterManager: {
// Provide each model that requires theaters with the right data
assign: function () {
// Get all theaters associated with each theater
App.theaterManager.addToCollection("theaters");
// Get all theaters associated with each movie
App.theaterManager.addToCollection("movies");
},
// Add theaters to a collection
addToCollection: function (collection) {
App.collections[collection].each(function (item) {
item.theaters = App.theaterManager.getTheaters(item.get(("theaters")));
});
},
// Returns a collection of Theaters models based on a list of ids
getTheaters: function () {
var args;
if (!arguments) {
return [];
}
if (_.isArray(arguments[0])) {
args = arguments[0];
} else {
args = Array.prototype.slice.call(arguments);
}
return new App.Theaters(_.map(args, function (id) {
return App.collections.theaters.get(id);
}));
}
}
};
$(function () {
App.init();
});