Reputation: 33
I want to show issues that I get from Ember.Deferred resolve. and pass it to the controller. But it shows error.
<script type="text/x-handlebars" id="magazines/show/issues">
{{#if issues}}
{{#each issue in issues}}
<li class="has-sub">
<a href="#">{{issue.name}}</a>
<ul style="display: none;">
<li {{action showGenericData issue}}><a href="#">Generic</a></li>
<li><a href="#">Inside</a></li>
</ul>
</li>
{{/each}}
{{else}}
<li>No Issue</li>
{{/if}}
Code for the model
var dfd = Ember.Deferred.create();
var issues = Em.A();
$.getJSON( App._api_path + "issues/" + mag_id ,
function(response){
response.forEach(function(m){
issues.pushObject(App.Issue.create(m));
});
dfd.resolve(issues);
});
return dfd;
Error in the console
Assertion failed: The value that #each loops over must be an Array. You passed <Ember.Deferred:ember285> ember-1.3.1.js:3285
Uncaught TypeError: Object [object Object] has no method 'addArrayObserver'
Please, help. Thanks...
Upvotes: 1
Views: 60
Reputation: 47367
If you were returning this from the model hook it would work fine. If you are returning it from some computed property you should just return issues.
var dfd = Ember.Deferred.create();
var issues = Em.A();
$.getJSON( App._api_path + "issues/" + mag_id ,
function(response){
response.forEach(function(m){
issues.pushObject(App.Issue.create(m));
});
dfd.resolve(issues);
});
return issues;
Upvotes: 1