Do action handlers not work directly on view instances?
Instead of attaching an action handler within the view, I want to attach it directly on the entire view itself.
Sample jsFiddle: http://jsfiddle.net/t3wdG/
UPDATE:
My goal is to delegate to specific functions (undo, redo in this case) on the parentView. The reason I have the buttonView is because on click on each button, I want to do something to it, for example add a css class to it.
So in effect, I want all my buttons to add a class to themselves on click and then delegate to separate functions on the parent view.
Is this possible using this approach?
Here is the updated jsFiddle: http://jsfiddle.net/xvkgk/
Ok, I don't think there is a built in ember way to do that, but check this jsfiddle, it seems work as you expect: http://jsfiddle.net/xvkgk/8/
The recommended solution is to make a custom view subclass. You can then add a click function the subclass that will handle click events automatically.
Related
I have an application where we'd like to use a <select> element to control which object is loaded in a detail route.
If this were a normal <ul>, like if I were using bootstrap's drop-down, using the #link-to helper would be perfect here, because I could use the active class to always automatically select the item that is loaded in the child route.
With a select element it's a little different. I'll probably need to write a view, I'm okay with that, but it occurs to me that parents aren't supposed to know about their children in ember, so how does a parent view get access to know which child view is currently selected?
Even a link to how the link-to helper is implemented could be helpful here.
Thanks!
If I'm interpreting this correctly, you're looking to change the URL when the <select> option changes.
With a combination of transitionToRoute, observes, and currentPath you can achieve this using the built in Ember.Select view class.
Here's a JSbin that might help:
http://emberjs.jsbin.com/jogadudase/2/edit
parents aren't supposed to know about their children in ember
Where does this come from?
I'm not 100% sure of what you want to accomplish, but you probably want to use one of this: Ember.ArrayController or Ember.CollectionView.
With either of those you can have control over children objects.
I want to embed two generic buttons like "Select" and "Cancel" to CMFCPropertyGridCtrl property line. Is there a painless way to do that?
Found a solution myself. You can use OnCreateEditor virtual method to send a custom control to a property. Note, that it will be shown on property edit. Another important note, that CMFCPropertyGridCtrl calls OnCreateEditor each time the user edits the property but before the control is destroyed it deletes the last received CWnd object itself. You should consider that. I have found no notes about that in MSDN CMFCPropertyGridProperty documentation (you know what to say).
I'm working on a events board app. Events are displayed in columns at the height matching the start time and pack into the space if there is more then one overlapping. Each event is a view and I want to have a div next to the view that shows and hides on hover.
I know how to bind to mouseEnter and mouseLeave to show and hide part of the template but I want to show something adjacent to my view/template not within it.
I've already got some computed properties on the view to place the event with the correct height and width so I don't want to add the popover inside the view.
Here is something to mess with http://jsbin.com/osoner/1/edit
Seems like something simple but I want to make sure I'm doing things the Ember way.
After messing a little with your provided jsbin, here the results.
Basically what I've done was adding a new popup css declaration wich do position the popup so that it appears outside the parent view, and also moved the {{#if...}} helper into the originating view.
If you want to go more fancy, checkout this jsfiddle wich uses the twitter boostrap popover.
Hope it helps.
My view contains an element. What is the best way to respond to mouseEnter and mouseLeave events for only that element?
Does ember want me to convert that element into a view?
Does ember want me to call this.$().on('mouseEnter', '.my-child-element', someHandler) and .off it myself in didInsertElement and willDestroyElement respectively?
Or am I missing a more appropriate approach?
There are several ways to approach this, but I always come to the conclusion that you create a view for anything that needs to respond to events. You could also use an action handler for very simple events in a template.
{{action "my_action" on="mousedown"}}
I would still recommend using a view though as you will most likely need to know more info about what happened and want access to the view and models bound to that element.
I am trying to detect events on table cells. I have found that I can receive the events when I use the {{action}} helper, but not when I define an event method on the view. Here is an example:
http://jsfiddle.net/9nWNQ/1/
Clicking the text "No action" should log a message, but it doesn't.
You might ask why I don't just use the action? The problem is that I want to detect multiple events and according to https://github.com/emberjs/ember.js/issues/569 I need to use a view.
I don't know why, but if you define your view as a by setting tagName: 'tr', it seems to work. http://jsfiddle.net/Sly7/ACzrY/#base
Perhaps your code produce an invalid html page, and the the click event is not triggered
Update: http://jsfiddle.net/Sly7/pX8ww/
I've replace the view tag with 'td' to behave more like the example