使用Ember.js 2.3.0从控制器检索数据时出现问题

时间:2016-02-27 19:52:01

标签: ember.js

我正在尝试学习本课程的余烬,并且我有以下控制器

import Ember from 'ember';

export default Ember.Controller.extend({
  title:'My Blog Post',
  body:'Body of the post',
  authors:['Author1', 'Author2', 'Author3'],
  comments:[
    {
      name:'name 1',
      comment:'comment 1'
    },
    {
      name:'name 2',
      comment:'comment 2'
    },
    {
      name:'name 3',
      comment:'comment 3'
    }
  ]
});

和模板:

<h1>{{title}}</h1>
<p>{{body}}</p>
<p>
  <strong>Authors:</strong>
  {{#each authors}}
    {{this}},
  {{/each}}
</p>
<h4>Comments</h4>
<ul>
{{#each comments as c}}
  <li><strong>{{name}}</strong> - {{comment}}</li>
{{/each}}
</ul>

它一直在产生这个输出:

My Blog Post

Body of the post

Authors: <my-app@controller:post::ember424>, <my-app@controller:post::ember424>, <my-app@controller:post::ember424>,

Comments

 -
 -
 -

我仔细检查所有内容,它与我看起来的演示相同,我也尝试使用{{#each comments as | c |}},{{每位作者为作者}} {{this.author}} ,尝试使用{{c.name}},同时尝试{{this.name}},{{this.c.name}}

我出错的任何想法?

提前致谢

1 个答案:

答案 0 :(得分:2)

将模板文件更改为:

<h1>{{title}}</h1>
<p>{{body}}</p>
<p>
  <strong>Authors:</strong>
  {{#each authors as |author|}}
    {{author}},
  {{/each}}
</p>
<h4>Comments</h4>
<ul>
{{#each comments as |c|}}
  <li><strong>{{c.name}}</strong> - {{c.comment}}</li>
{{/each}}
</ul>