0

I am new to Ember and I am not sure how to do things the Ember way so I turn to you.

My problem:
I have a sidebar, I created a View for it. I have two buttons on the sidebar for the moment. I added an action for each button on it. I am not sure if I should handle it on controller or on view. I want on clicking one of these button, a new view to be inserted that would open a pop up menu and also the button that called the action to remain in a selected state.

I am not very sure how to do this. I tried to target the view with the action but I can't have access to the target element or at least I don't know how to access it (tried this.$()).

What way do you suggest to follow?

Andrew
  • 6,254
  • 16
  • 59
  • 93

1 Answers1

1

User 'actions' are handled with methods on a Controller or a Route. You should put them in an actions hash:

App.MyController = Ember.ObjectController.extend({
    actions: {
        doSomething: function() {
            // do it here
        }
    }
});

Ember manipulates the DOM and inserts views automatically based on resources and routes. If you don't want to use the router, you can manually control the view hierarchy, but I'd suggest getting more familiar with Ember routing before you try manual views.

If I were you, I'd create a Component that handled the button. You will have a reference to the DOM element in the didInsertElement callback: http://emberjs.com/api/classes/Ember.Component.html#event_didInsertElement

Steve H.
  • 6,912
  • 2
  • 30
  • 49