3
votes

I have this view MessagesView where I want to render n child views each of type MessageView.

The handlebars template section, for MessagesView looks like so:

{{#each message in controller}}
    {{#link-to "message" message class="list-group-item"}}
        {{view view.messageView}}
    {{/link-to}}
{{/each}}

The view definitions are pretty straightforward, the only interesting bits are probably:

MessagesView = Ember.View.extend({
    messageView: MessageView,
    ...
});

MessageView = Ember.View.extend({
    messageId = 0;
});

I want to initialize MessageView.messageId to a particular value in the {{#each}} helper to message.id. Something like this hypothetical block of code:

{{view view.messageView({messageId: message.id})}}

I don't see any way to do that. Could someone point me to a scheme that would allow me to do that or perhaps outline any other standard practice to doing so?

EDIT:


I see a viewName property that can be passed to the child view through the {{view}} helper like so, here:

{{#view viewName="aChildByName"}} hi {{/view}}

I guess I'm asking how to send other generic properties to the child view.

EDIT 2


Mostly for future visitors, this is mentioned in the discussion of Components.

1

1 Answers

4
votes

You can accomplish this by just adding it as an "attribute" when invoking the view.

{{#each message in controller}}
    {{#link-to "message" message class="list-group-item"}}
        {{view view.messageView messageId=message.id}}
    {{/link-to}}
{{/each}}

See this fiddle for a sample.