Wednesday, 4 September 2013

Link a controller to a dynamically added view

Link a controller to a dynamically added view

Hi and thanks a lot for your answers! I am trying to understand Ember and
its structure.
And this is where I am stuck with : I have a view that can be added
anywhere and anytime in my web-app (modal view). I want to link this view
with a specific controller to handle event, state and other behaviors.
But I didn't find how it is possible! Is this an error in the structure of
my application or is it a problem that comes from somewhere else? (me?)
Here is the relevant part of the code.
/views/post_news_popup.js
App.PostNewsPopupView = Ember.View.extend({
templateName: '_post-news',
close: function() { /*...*/ },
save: function() { /*...*/ }
});
index.html

...
<script type="text/x-handlebars" data-template-name="_post-news">
<form {{ action "save" on "submit"}}>
{{view Ember.TextField valueBinding="name" placeholder="Fill in a
name..."}}
{{view Ember.TextArea valueBinding="description" placeholder="Fill
in a description..."}}
<button >Cancel</button>
<button>Post news</button>
</form>
</script>
controllers/post_news_controller.js
App.PostNewsPopupController = Ember.ObjectController.extend({
actions: {
close:function() { /*...*/ },
save:function() { /*...*/ }
}
});
I didn't find the way to link PostNewsPopupController to
PostNewsPopupView. I tried a lot of things, but neither functions of
controller nor functions of view were called.
I know that controllers are automatically set when browsing to a route,
but here there is no specific route for this and I don't want to put all
that code in ApplicationController.
Thank you for helping me and sorry if question is... stupid! :D

No comments:

Post a Comment