【问题标题】:Do Ember.js support model for Application route?Ember.js 是否支持应用程序路由的模型?
【发布时间】:2014-10-01 01:47:44
【问题描述】:

在我的 Ember Application Handlebars 模板中,我需要一些模型数据来显示。在索引或其他路由中,这些类型的代码可以工作,但在应用程序路由中它们不起作用。 申请途径

App.ApplicationRoute = Ember.Route.extend({
 model: function()
 {
  return this.store.findAll('archive');
 }
});

应用模板:

<script type="text/x-handlebars" data-template-name="application">
 {{#each}}
  {{title}}
 {{/each}}
</script>

DS.模型:

App.ApplicationAdapter = DS.FixtureAdapter;

App.Archive = DS.Model.extend({
  title: DS.attr('string'),
  day:   DS.attr('number')
});

App.Archive.FIXTURES = [
 {
  "id":1,
  "title": "First title",
  "day": 06
 },
 {
  "id":2,
  "title": "Second title",
  "day": 08
 }
];

我找不到问题在哪里。在 Ember 中,我可以使用模型作为应用程序模板吗?

【问题讨论】:

  • 您是否在某处定义了不是数组控制器的应用程序控制器?

标签: ember.js model handlebars.js


【解决方案1】:

是的,毫无疑问,如果您定义了一个不是 ArrayController 的应用程序控制器,那么您的代码无法正常工作的主要原因是。

示例:http://emberjs.jsbin.com/OxIDiVU/1115/edit

【讨论】:

  • 我正在使用App.ApplicationController = Ember.Controller.extend({})
  • 如果你把它切换到App.ApplicationController = Ember.ArrayController.extend({})你应该很高兴!
  • 现在我得到了一些其他的问题。我收到Error while processing route: index undefined is not a function TypeError: undefined is not a function。实际上我的整个应用程序不使用除了应用程序模板之外的余烬数据,因为它的数据不是动态的。其他路由模型使用 ajax json 填充。如果我不使用任何模型作为应用程序模板,一切都会很好。
  • 最后让它工作。我的 json 格式有一些问题。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多