1

実際、ビューがコレクション ビューの最初または最後のアイテムをマークできるようにするメソッドを探していて、これを見つけました。最後の要素? .しかし、itemViewClass テンプレートの attrs(classNames など) を JavaScript で定義したくありません。{{itemView}} ヘルパーなどを使用して itemView テンプレートを定義できますか?

{{#collection contentBinding="dataList" tagName="ol" classNames="list" itemViewClass="ItemView"}}
    {{#itemView classNames="item" classNamesBinding="isLastItem:last"}}
        item templates
    {{/itemView}}
{{/collection}}

これは別の方法で解決できますが、組み込みのサポートが見つかるかどうか知りたいだけです。そして、私は長い間検索していますが、Ember.Handlebars.collectionのドキュメントが見つかりません。最新の API ドキュメントにはありません。

4

1 に答える 1

0

Emberjs のマスター バージョンから始めて、カスタム ハンドルバーの「バインドされた」ヘルパーを使用してみてください。次のようになります。

{{#each item in collection}}
    {{#isLastElement item}}
        template if last
    {{else}}
        template if not
    {{/isLastElement}}    

    both templates
{{/each}}


Ember.Handlebars.registerBoundHelper('islastElement', 
    function(item, options) {
     if(functionTellingIfThisIsLastElement(item))
          return options.fn(this);
     else
          return options.inverse(this);
    }
);

これは、functionTellingIfThisIsLastElementを使用して、アイテムのコレクションまたはプロパティを調べる別の方法です。コレクションにアクセスするには、コードに応じて、適切なコンテキスト + パラメータを取得するために、ここでいくつかのものを変更する必要があります。

于 2012-12-21T08:19:16.453 に答える