javascript - value that #each loops must be an array, controller passed - Stack Overflow

I get these error messages upon loading the page:Assertion failed: The value that #each loops over must

I get these error messages upon loading the 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 quite simple:

TSLibrary.Snippet = DS.Model.extend({
  title: DS.attr('string')
});

TSLibrary.Snippet.FIXTURES = [{id: 1, title: 'Learn Ember.js'}];

My app 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');
  }
});

So my guess is that this.store.find('snippet') is not returning the right data. I've also installed the Ember debug extension in Chrome and it shows me all the right data in my model.

Ember version: 1.0.0
Ember Data version: v1.0.0-beta.1-140-ga51f29c a51f29c (2013-09-07 16:34:55 -0700)
Handlebars version: 1.0.0
jQuery version: 1.10.2

I get these error messages upon loading the 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 quite simple:

TSLibrary.Snippet = DS.Model.extend({
  title: DS.attr('string')
});

TSLibrary.Snippet.FIXTURES = [{id: 1, title: 'Learn Ember.js'}];

My app 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');
  }
});

So my guess is that this.store.find('snippet') is not returning the right data. I've also installed the Ember debug extension in Chrome and it shows me all the right data in my model.

Ember version: 1.0.0
Ember Data version: v1.0.0-beta.1-140-ga51f29c a51f29c (2013-09-07 16:34:55 -0700)
Handlebars version: 1.0.0
jQuery version: 1.10.2

Share Improve this question asked Sep 8, 2013 at 21:02 ComFreekComFreek 29.5k18 gold badges107 silver badges157 bronze badges
Add a ment  | 

2 Answers 2

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

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

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

This one is just 'snippets', which correctly uses the SnippetsRoute that you have defined.

I found the solution by accident, now:

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

has to be

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745274375a4619945.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信