简体   繁体   中英

Ember.js: no model on handmade controller

my Problem is: If I write my on controller in Ember I'm not able to access the model in the template. If I use the generated controller everything works fine. I already tried this but it didn't work.

This are my used Versions:

Ember : 1.4.0
Handlebars : 1.3.0
jQuery : 1.10.2

Here some code (route):

App.ArticlesCreateRoute = App.AuthenticateRoute.extend({
setupController: function(controller, model) {
    controller.set('content', model);
},
renderTemplate: function() {
    this.render("side-bar", {into: "application" , outlet: "sidebar",  controller: "articles.create"  });
    this.render("articles-create");
},
model: function(params) {        
    return App.Model.get(this,"articles.create","/api/categories/list");
   //return [{id: 1, select_name: "test"},{ id: 2, select_name: "Man"}];
}
});

controller:

App.ArticlesCreateController = Ember.ArrayController.extend({
navigation: [
           {controller: "articles.page", text: "Übersicht" , hint: "", icon: "fa fa-laptop"},
           {controller: "articles.create", text: "Artikel erstellen" , hint: "", icon: "fa fa-plus"}
          ],
publish: [{ id: "false", name: "Nein" }, {id: "true", name: "Ja"}], 
formats: [{ id: "html", name: "HTML" }, {id: "md", name: "Markdown"}], 

});

template:

 <table>
  {{#each}}
    <tr>
         <td>{{id}}</td>
         <td>{{select_name}}</td>             
     </tr>
 {{/each}}
 </table>

I hope someone can help me...

From what I see you need to specify the controller also for the second render call from renderTemplate like this:

...

renderTemplate: function() {
  this.render("articles-create");
    this.render("side-bar", {into: "application" , outlet: "sidebar",  controller: "articles.create"  });
    this.render("articles-create", {
      controller: "articles.create"
    });
},

...

You can check out here for a working jsbin . Please follow the Create article link. I added some stuff to make it work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM