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:

  1. whatever trying loop on not array. template can see looping on content property of our controller. looks don't have arraycontroller set , dealing objectcontroller. confirm using ember inspector

  2. where 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, generated objectcontroller us. if explicitly define applicationcontroller of type arraycontroller, ember use our controller instead of generating 1 itself.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -