2016-02-27 66 views
0

我努力學習燼這個課程之後,我有以下控制器問題檢索從控制器的數據使用Ember.js 2.3.0

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: <[email protected]:post::ember424>, <[email protected]:post::ember424>, <[email protected]:post::ember424>, 

Comments 

- 
- 
- 

我仔細檢查了所有內容,它與我看起來相似,我也嘗試使用{{#each comments as | c |}},{{每個作者作爲作者}} {{this.author}},嘗試使用{{c.name}},也嘗試{{this.name}},{{this.c.name}}

任何想法,我哪裏錯了?

在此先感謝

回答

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> 
+0

感謝@Dan_C,我不得不更新{{#each批示| C |}},但我沒有用{{c.name}}做了詭計 – Icaro

+0

@lcaro,很高興幫助! :) –

相關問題