I’ve got an ember application that needs to manage multiple chat windows. A window for each active chat is created within an {{#each}} loop. This is straightforward enough. The place that I’m having trouble is sending the chat message when the user presses enter.
The window looks like this
{{#each chats}}
... stuff to display already existing chats...
{{view Ember.TextField valueBinding="text" action="sendChat"}}
<button {{action sendChat this}}> Send </button>
{{/each}}
This works fine for the button, since I can pass this to it. By default the function defined in the textfield view action just gets the text within that textfield, which is not enough in this case. Since there can be multiple chat windows open, I need to know which window the message was typed into. Is it possible to pass this to the textfield action function? (or can you suggest a different way to solve this problem?)
AddcontentBinding="this"to the definition of the view, like:EDIT
Ember master already has this change, but the official downloadable verstion still don’t.. so you will need to subclass the
Ember.TextFieldand change itsinsertNewlineto achieve required functionality:After that, the action handler will receive additional argument, the view:
and in controller:
You may use ember master instead of subclassing
Ember.TextField..I hope the ember guys will release the next version soon..