I’d like to have multiple views reacting to something that the user does. So I thought, a global custom event would be right thing to achieve my goal. If there’s something better, I’m happy for other ideas.
According to the documentation, I should be able to add custom events to my Ember.js application like that:
Mobile = Em.Application.create({
customEvents: {
"customevent": "customevent"
}
});
Unfortunately, the documentation stops there and doesn’t tell me how to fire the event and bind something to it. So tried it myself and created a view that should “listen” to it:
Mobile.HeaderView = Em.View.extend({
templateName: "header",
customevent: function() {
return console.log("Custom event has been fired!");
}
});
At the end, I fired the event in my console:
$.event.trigger("customevent")
Unfortunately, nothing happens.
Can anybody tell me what I’m doing wrong? Or if there’s even a better way to get what I want?
I have solved my problem using
Em.Bindinglike Luke Melia demonstrates in his slides:http://www.lukemelia.com/devblog/archives/2012/08/23/architecting-ember-js-apps/
Code example from another StackOverflow question: