2013-07-08 8 views
5

CollectionViewアイテムのリストを作成し、CollectionViewtemplateNameプロパティで指定されたテンプレートにレンダリングしようとしています。しかし、私はそれを働かせることはできません。Ember.CollectionViewでテンプレートを使用する方法

が、それは次のようになります。このようなテンプレートと

App = Ember.Application.create({}); 

App.ItemView = Ember.View.extend({ 
    templateName: 'item_template', 
    tagName: 'li' 
}); 

App.CollectionViewTest = Ember.CollectionView.extend({ 
    templateName: 'collection_template', 
    itemViewClass: App.ItemView, 

    content: [ 
     { title: 'Item 1' }, 
     { title: 'Item 2' } 
    ] 
}); 

<script type="text/x-handlebars" data-template-name="application"> 
    <h1>Testing CollectionView TemplateName</h1> 
    {{collection App.CollectionViewTest}} 
</script> 

<script type="text/x-handlebars" data-template-name="collection_template"> 
    <h2>The CollectionView Template</h2> 
    <ul> 
     {{outlet}} 
    </ul> 
</script> 

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

ことがあるので、私はEmber.ViewApp.CollectionViewTestを変更しない限り、<h2>は、レンダリングされることは決してありませんが、その後、明らかにリスト項目はありません。

これはバグですか?または私は何かを逃している? Ember.CollectionViewEmber.ContainerViewのサブクラスであるので、それはそれ自身のテンプレートを持っていませんhttp://jsfiddle.net/S46vH/

+0

と置き換えてください。http://jsfiddle.net/S46vH/は基本的に空白ですが、ここにリンクを投稿する前に最新バージョンを保存しましたか? – intuitivepixel

+0

oops、no。すべきだった:http://jsfiddle.net/S46vH/1/しかし問題は今解決した。どうもありがとう。 – rainbowFish

答えて

4

: -

ここでjsのフィドルはコードであります。 APIドキュメントから

テンプレート、TEMPLATENAME、defaultTemplate、レイアウト、layoutName又はdefaultLayoutプロパティコンテナビューにレンダリングされているテンプレートやレイアウトをもたらさないであろう。 Ember.ContainerViewのDOM表現のHTMLコンテンツは、その子ビューのレンダリングされたHTMLのみになります。

この作業を行うには、collection_templateマークアップをアプリケーションテンプレートに移動するか、部分的にすることができます。次に{{outlet}}{{collection App.CollectionViewTest}}

+3

ああ、意味があります。私は 'template'と' templateName'の両方がEmber APIの 'CollectionView'ページのプロパティとしてリストアップされているという混乱を受けました。ヒントをありがとう! – rainbowFish

+0

ええ、それは私を数回上げてしまった。 –

関連する問題