Я изучаю Backbone.js в первый раз, и у меня возникла проблема с попыткой получить пользовательское событие от запуска (или из представления от распознавания, когда оно было запущено )?
Код моей коллекции можно посмотреть здесь:https://github.com/Integralist/Backbone-Playground/blob/master/Assets/Scripts/App/main.js#L72-86который при инициализации запускает пользовательское событие collection:init
.
var Contacts = Backbone.Collection.extend({
model: Contact,
initialize: function(){
this.trigger('collection:init');
this.bind('add', this.model_added, this);
},
model_added: function(){
console.log('A new model has been created so trigger an event for the View to update the
Но позже в моем представлении, где я слушаю это событие, я не могу заставить функцию populate
срабатывать:https://github.com/Integralist/Backbone-Playground/blob/master/Assets/Scripts/App/main.js#L90-107
var ContactsView = Backbone.View.extend({
initialize: function(){
console.log(contacts.models, 'get initial model data and populate the select menu?');
},
events: {
'collection:init': 'populate',
'change select': 'displaySelected'
},
populate: function(){
console.log('populate the
Любые идеи, что я делаю неправильно?