Meaning that #each loops must be an array, the controller passed

I get these error messages when loading a page:

Assertion failed: The value that #each loops over must be an Array. You passed (generated snippets.index controller) ember-1.0.0.js:394 Uncaught TypeError: Object [object Object] has no method 'addArrayObserver' 

Here is my template code:

 <script type="text/x-handlebars" data-template-name="snippets/index"> {{#each}} {{title}} {{/each}} </script> 

My Snippet model is pretty simple:

 TSLibrary.Snippet = DS.Model.extend({ title: DS.attr('string') }); TSLibrary.Snippet.FIXTURES = [{id: 1, title: 'Learn Ember.js'}]; 

My application and my router:

 window.TSLibrary = Ember.Application.create(); TSLibrary.ApplicationAdapter = DS.FixtureAdapter.extend(); // --- TSLibrary.Router.map(function () { this.resource('snippets', { path: '/' }, function () { }); }); TSLibrary.SnippetsRoute = Ember.Route.extend({ model: function () { // My guess is that this does not return the expected array // // This logs 'Class {toString: function, constructor: function, reason: null, isPending: undefined, isSettled: undefined…}' console.log(this.store.find('snippet')); return this.store.find('snippet'); } }); 

Therefore, I assume that this.store.find('snippet') does not return the correct data. I also installed the Ember debug extension in Chrome, and it shows me all the data I need in my model.

Amber Version: 1.0.0
Ember Data version: v1.0.0-beta.1-140-ga51f29c a51f29c (2013-09-07 16:34:55 -0700)
Version for pens: 1.0.0
JQuery Version: 1.10.2

+4
source share
2 answers
 TSLibrary.Router.map(function () { this.resource('snippets', { path: '/' }, function () { }); }); 

This path creates the "snippets.index" path, which requires a Route called SnippetsIndexRoute.

 TSLibrary.Router.map(function () { this.resource('snippets', { path: '/' }); }); 

These are just “fragments” that correctly use the SnippetsRoute described by you.

+5
source

I found the solution by accident, now:

 TSLibrary.Router.map(function () { this.resource('snippets', { path: '/' }, function () { }); }); 

should be

 TSLibrary.Router.map(function () { this.resource('snippets', { path: '/' }); }); 
0
source

Source: https://habr.com/ru/post/1501204/


All Articles