1

编辑:问题被撤销。CollectionViews 作为 ContentViews 的子类,不尊重布局,令人沮丧。

CollectionViews 似乎不适用于布局。例如:

测试用例:http: //jsfiddle.net/73sWp/

模板:

<script type="text/x-handlebars" data-template-name="layoutTest">
    <div class="my-collection">
        <h1>{{title}}</h1>
        {{yield}}
    </div>
</script>       

<script type="text/x-handlebars" data-template-name="layoutTest-child">
    <div class="an-item">
        Hi there.
    </div>
</script>

脚本:

var TestView = Ember.CollectionView.extend({
    layoutName: "layoutTest",
    title: "My Collection",
    childViews: [
        Ember.View.create({
            templateName: 'layoutTest-child'
        }),
        Ember.View.create({
            templateName: 'layoutTest-child'
        })
    ]
});
$(function () {
    TestView.create().appendTo(document.body);
});

预期的:

<div class="my-collection">
    <h1>My Collection</h1>
    <div class="an-item">
        Hi there.
    </div>
    <div class="an-item">
        Hi there.
    </div>
</div>

实际的:

<div class="an-item">
    Hi there.
</div>
<div class="an-item">
    Hi there.
</div>

我错过了一些明显的东西吗?

4

1 回答 1

3

Layouts are template based and CollectionViews have been intended to be used without templates.

This issue has been discussed a bit and I think the consensus is that we'd like to support using layouts with ContainerViews.

A pull request has been submitted that adds this functionality: https://github.com/emberjs/ember.js/pull/928

于 2012-06-02T23:27:08.873 回答