0

Using Ember.js I get an endless loop with the following code:

Controller:

App.activityDetailsController = Em.Object.create({
  activityBinding :     'App.navController.selectedActivity',

  data : function(){
    var things = new Array();
    if(this.activity){
      var info = this.activity.get('info');
      var len = info.length;
      for(var i=0; i<len; i++){
        for(prop in info[i]){
          things.push({"key": prop, "value" : info[i][prop]});       
        }
      }
    }

    return things;
  }.property('activity')    
})

View:

App.ActivityDetailsView = Em.View.extend({
  templateName :        'activity-details',
  activityBinding :     'App.activityDetailsController.activity',
  dataBinding :         'App.activityDetailsController.data'

})

Template:

  <script type="text/x-handlebars" data-template-name="activity-details">
    <div id="info">
      {{#each data}}
          {{key}}: {{value}}<br />
      {{/each}}
    </div>
  </script>

When trying to load this page, the 'data' function in the controller is called endlessly.

If I remove the {{#each}}{{/each}} block from the view, there is no problem and using {{data.length}} in the template gives the correct output.

Any ideas why this loops endlessly? If I remove 'activity' from the property call, it the problem is the same.

Thanks,

1
  • Wait, won't #each data return a function, not the value of that function? If you want to return a value, why not make it a computer property? Commented Feb 20, 2012 at 18:13

1 Answer 1

1

Make your "data" property cacheable(). See ebryn's answer to a related question for the reason why.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.