lundi 9 novembre 2015

Ember Computed properties and Handlebars templates

In my Ember Controller, I have 2 computed properties (CP) as below;

itemsWithData: function() {
    var dataItems = [];

    return dataItems;
}.property('containsFailure'),
someArray: function() {
    var items = this.get('itemsWithData');
    var someArray = [];

    return someArray;
}.property('itemsWithData')

Now in my Ember Handlerbars template, while I only use someArray CP to iterate on and display values, I am not using the other CP (i.e. itemsWithData)

But if I do not refer itemsWithData in my template, the same is not getting executed in my controller (so even someArray does not execute since it depends on itemsWithData)

It only executes if I explictly add a dummy reference as below;

{{#each itemsWithData as |data|}}
{{/each}}

Is that how CP works in controllers/templates ? I need a way such that I do not have to add this dummy code in my template.




Aucun commentaire:

Enregistrer un commentaire