Domanda

I have multiple template files. What I am trying to achieve is to iterate over the properties of a model which is associated with a different view. For example I have a model for messages like this

Cards.Message = DS.Model.extend({
   message: DS.attr('string'),
   font_size: DS.attr('string'),
   font_face: DS.attr('string'),
   text_color: DS.attr('string')
});

Now I am in another template which is recipient. So its controller is Recipient controller and the model associated with it is recipient. But I want to access the values of Message model here. So I am trying to do something like this here.

{{#each item in message}}
        {{item.message}}
{{/each}}

But nothing is being displayed here. I think we have to tell the handles bar template that we want to access the property of different model but how can we do this?

È stato utile?

Soluzione

You'll need to add the MessageController to the RecipientController by adding it through the needs property, like this:

App.RecipientController = Ember.ObjectController.extend({
    needs:['message'];
});

You'll then be able to access the properties of the message controller with a path like this: controllers.message.model.

This won't cause your messages to load though. You'll still need to make sure they're loaded in the route.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top