Reputation: 1414
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,
Upvotes: 0
Views: 482
Reputation: 2438
Make your "data" property cacheable()
. See ebryn's answer to a related question for the reason why.
Upvotes: 1