javascript - EmberJS - Assertion failed: The value that #each loops over must be an Array. You passed (generated application controller) -
i'm struggling model's fixture data render template, receive error above when try each loop in template:
{{#each}} {{title}} {{/each}}
i have set router so:
application.router.map(function() { this.resource('application', { path: '/' }); }); application.applicationroute = ember.route.extend({ model: function() { return this.store.find('applicationmodel'); } });
and model setup so:
application.applicationmodel = ds.model.extend({ title: ds.attr('string') }); application.applicationmodel.fixtures = [ { id: 1, title: 'title-1' }, { id: 2, title: 'title-2' } ];
can tell me i'm doing wrong?
thanks
try this:
{{#each content}} {{title}} {{/each}}
and
app.applicationcontroller = ember.arraycontroller.extend({}) application.applicationroute = ember.route.extend({ model: function() { return this.store.find('applicationmodel'); }, setupcontroller: function(controller, model) { controller.set('content', model); } });
edit: elaborate per @andy hayden's request in comments:
the error (emberjs - assertion failed: value #each loops on must array. passed (generated application controller)
) gives 2 clues:
whatever trying loop on not array. template can see looping on
content
property of our controller. looks don't havearraycontroller
set , dealingobjectcontroller
. confirm using ember inspectorwhere controller come from? ember auto generate controllers if needs 1 , don't explicitly define it. can see that is, in fact, happened, looking @ error message (
generated application controller
). ember wouldn't know if want represent single object or array, generatedobjectcontroller
us. if explicitly defineapplicationcontroller
of typearraycontroller
, ember use our controller instead of generating 1 itself.
Comments
Post a Comment