我的问题是:如果我在Ember中编写我的控制器,我无法访问模板中的模型。如果我使用生成的控制器一切正常。我已经尝试了this,但它没有用。
这是我使用的版本:
Ember:1.4.0
把手:1.3.0
jQuery:1.10.2
这里有一些代码(路线):
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"}];
}
});
控制器:
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"}],
});
模板:
<table>
{{#each}}
<tr>
<td>{{id}}</td>
<td>{{select_name}}</td>
</tr>
{{/each}}
</table>
我希望有人可以帮助我...
答案 0 :(得分:1)
从我看到你需要为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"
});
},
...
您可以在这里查看工作jsbin。请关注Create article
链接。我添加了一些东西来使它工作。