Ember view with dynamic class names

Considering the following:

Parent template:

{{view App.SomeView id="42" panelClass="default"}}

View template:

        <div class="col-md-3 col-sm-6">
            <div class="panel panel-{{panelClass}}">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        {{name}}
                    </h3>
                </div>
                <div class="panel-body">
                    {{description}}
                </div>
            </div>
        </div>

View JS:

App.SomeView = Ember.View.extend({
    templateName: 'views/some-view'
});

How can I achieve output HTML where the panel class gets set properly? At the moment it doesn't work because it wants to bind, so it inserts the ember metamorph script tags, instead of just plain text for the panel class.

Also, the template is wrapped in an extra div. How would I modify it so that the ember-view wrapping div is actually the first div in the template (the one with col-md-3 col-sm-6)?


The bind-attr helper exists for that reason. Here's the guide entry.

<div {{bind-attr class=":panel panelClass"}}></div>

Also, not sure if you can use a prefix on panelClass in the template. If might be easier just to use a computed property to add the panel- beforehand.


I'm sorry, I didn't see your second question about the extra div. The guide explains here how to extend the element.

App.SomeView = Ember.View.extend({
    classNames: ['col-md-3', 'col-sm-6']
});
链接地址: http://www.djcxy.com/p/73460.html

上一篇: 我如何在渲染管道之外使用模板

下一篇: 用动态类名填充视图