2017-07-12 103 views
-1

我是新來的燼,似乎無法弄清楚爲什麼我的列表不會顯示。這裏是我的路線頁面上創建模型的代碼:不顯示模型信息

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    model: function(){ 
     return ['Ford', 'tesla','lexus']; 
    } 
}); 

,這是我的模板頁面

<h1>Cars</h1> 
<ul> 
    {{#each car in model}} 
     <li>{{car}}</li> 
    {{/each}} 
</ul> 

但出於某種原因正在顯示任何信息。有人注意到我沒有看到的東西嗎?提前致謝!

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

    {{/each}} 
</ul> 

export default Ember.Controller.extend({ 
action:{ 
    sayHello: function(){ 
     alert('Hello') 
    }, 
    toggleBody: function(){ 
     this.toggleProperty('isShowingBody'); 
    }, 
    submitAction: function(){ 
     alert(this.get('name')); 
     alert(this.get('comment')); 
    } 
}, 

title: 'My Bliog Post', 
body: 'My body of work is endless i tell you', 
authors: ['william','robert','michelle'], 
created: new Date(), 
comments: [ 
    { 
     name: 'Evan', 
     comment: 'Hey what is new ' 
    },{ 
     name: 'Evan', 
     comment: 'Hey ith you' 
    },{ 
     name: 'Evan', 
     comment: 'Hey what is n' 
    } 
] 

});

+0

按照燼指南。 https://guides.emberjs.com/v2.14.0/templates/displaying-a-list-of-items/我認爲你使用的語法是在舊版本的ember中使用的。多數民衆贊成已棄用,現在刪除 – kumkanillam

回答

1

你在你的每個語句有一個錯誤:

{{#each model as |car|}} 
{{car}} 
{{/each}} 

例如:https://ember-twiddle.com/ed1ea81eb660a3ea2088c535961f2e2f?openFiles=templates.application.hbs%2C

+0

這有助於..但我有其他類似的問題有相同的問題。我將修改我的原始文章 – user3255746

+0

,正如@kumkanillam在評論中所說的那樣,在每條語句中使用的語法都是錯誤的,您需要添加管道,我已經使用模板更新更新了旋轉。 [更新示例](https://ember-twiddle.com/ed1ea81eb660a3ea2088c535961f2e2f?openFiles=templates.application.hbs%2C)以及您的控制器中存在拼寫錯誤:action => actionS – kubz