[英]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. 我的问题是:如果我在Ember中编写on控制器,则无法访问模板中的模型。 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 灰烬:1.4.0
Handlebars : 1.3.0 车把:1.3.0
jQuery : 1.10.2 的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的第二次渲染调用指定控制器,如下所示:
...
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 . 您可以在这里查看可用的jsbin 。 Please follow the Create article
link. 请点击Create article
链接。 I added some stuff to make it work. 我添加了一些东西使其工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.