ember.js - Link a controller to a dynamically added view -


hi , lot answers! trying understand ember , structure.

and stuck : have view can added anywhere , anytime in web-app (modal view). want link view specific controller handle event, state , other behaviors.

but didn't find how possible! error in structure of application or problem comes somewhere else? (me?)

here relevant part of code.

/views/post_news_popup.js

app.postnewspopupview = ember.view.extend({     templatename: '_post-news',     close: function() { /*...*/ },     save: function() { /*...*/ } }); 

index.html

{{view app.postnewspopupview}}  ...  <script type="text/x-handlebars" data-template-name="_post-news">     <form {{ action "save" on "submit"}}>         {{view ember.textfield valuebinding="name" placeholder="fill in name..."}}         {{view ember.textarea valuebinding="description" placeholder="fill in description..."}}         <button {{action 'close'}}>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 way link postnewspopupcontroller postnewspopupview. tried lot of things, neither functions of controller nor functions of view called.

i know controllers automatically set when browsing route, here there no specific route , don't want put code in applicationcontroller.

thank helping me , sorry if question is... stupid! :d

you should add following code route connected template, in using view helper (i don't name :-):

add route:

rendertemplate: function(controller, model) {     this._super(controller, model);      this.render('postnewspopup', {       outlet: 'modaloutlet',     }); } 

add outlet template want view added:

{{outlet modaloutlet}} 

this render postnewspopupview modaloutlet connected postnewspopupcontroller.

further informations:

the render method takes more arguments. here full blown example of render method:

this.render('your', {   // template/view render   into: 'index',          // template render   outlet: 'someoutlet',       // name of outlet in template   controller: this.controllerfor("another")  // controller use template }); 

this render view of type app.yourview index template outlet named someoutlet. view connected controller instance app.anothercontroller.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -