2012-08-27 22 views
3

我是新來的燼,我試着用代碼玩一下,所以我從網站上下載了作爲起始模板的入門工具包。Ember.js Handlebars.helpers.collection不能正常工作

我試圖使用的CollectionView餘燼車把幫手,我複製粘貼示例代碼,但我看到的是「Hi」 3次無名稱:

http://docs.emberjs.com/symbols/Handlebars.helpers.html#method=.collection

我在做什麼有問題?

<script type="text/x-handlebars"> 
    {{#collection contentBinding="App.items"}} 
     Hi {{content.name}} 
    {{/collection}} 
</script> 


<script> 
App = Ember.Application.create(); 

App.items = [ 
    Ember.Object.create({name: 'Dave'}), 
    Ember.Object.create({name: 'Mary'}), 
    Ember.Object.create({name: 'Sara'}) 
] 
</script> 

謝謝!

+1

杜佩:http://stackoverflow.com/questions/12028209/content-name-returns-empty-for-collection/12028795#12028795 – Rajat

+0

的可能重複的[灰燼.js:把手沒有顯示](http://stackoverflow.com/questions/11818116/ember-js-handlebars-displays-nothing) –

回答

5

這是一個關於方法方面的問題是在在解釋燼的最新版本管理:

content.name returns empty for collection

總之,你需要做到這一點在你的模板,而不是:

<script type="text/x-handlebars"> 
    {{#collection contentBinding="App.items" }} 
     Hi {{view.content.name}} 
    {{/collection}} 
</script>​ 

小提琴顯示它:http://jsfiddle.net/XdHRS/

對於你可以只使用每個相同的目的:

<script type="text/x-handlebars"> 
    {{#each App.items }} 
     Hi {{name}} 
    {{/each}} 
</script>​ 

小提琴表示它:http://jsfiddle.net/e3UTt/13/

+1

這應該是在燼文檔 – Aras