Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong assertion: The value that #each loops over must be an Array. #4365

Closed
earthquakesan opened this issue Feb 13, 2014 · 8 comments
Closed

Comments

@earthquakesan
Copy link

The problem is that I can't pass the object to {{#each}} Handlebarsjs conditional, because it raises exception in ember.js code. Handlebarsjs {{#each}} can iterate through objects, here is the excerpt from Handlebars v1.3.0: http://pastebin.com/UTtvnhcB

The place in ember.js where this occurs:

@module ember 
@submodule ember-handlebars

Ember.Handlebars.EachView = Ember.CollectionView.extend(Ember._Metamorph, {
...
_assertArrayLike: function(content) {
    Ember.assert("The value that #each loops over must be an Array. You passed " + content.constructor + ", but it should have been an ArrayController", !Ember.ControllerMixin.detect(content) || (content && content.isGenerated) || content instanceof Ember.ArrayController);
    Ember.assert("The value that #each loops over must be an Array. You passed " + ((Ember.ControllerMixin.detect(content) && content.get('model') !== undefined) ? ("" + content.get('model') + " (wrapped in " + content + ")") : ("" + content)), Ember.Array.detect(content));
  },
...
@module ember
@submodule ember-views

Ember.CollectionView = Ember.ContainerView.extend({
...
  _contentDidChange: Ember.observer('content', function() {
    var content = get(this, 'content');

    if (content) {
      this._assertArrayLike(content);
      content.addArrayObserver(this);
    }

    var len = content ? get(content, 'length') : 0;
    this.arrayDidChange(content, 0, null, len);
  }),
...
@wagenet wagenet added the bug label Apr 2, 2014
@rwjblue
Copy link
Member

rwjblue commented Apr 10, 2014

To be honest, I was not aware that you could use the {{each}} helper to iterate keys on an object in standard Handelbars, but we are not utilizing the {{each}} helper that comes with Handlebars, we are using our own independent helper (see here) that does not have the same object key iteration semantics as the one that you linked to.

I believe that this is just a fundamental difference between the Ember {{each}} helper and the Handlebars helper, and not really a bug.

I'm happy to reopen if there is something I'm missing here.

@rwjblue rwjblue closed this as completed Apr 10, 2014
@macool
Copy link

macool commented May 14, 2014

Just ran into this. What about people that are used to use {{each}} to iterate on an object? It's on handlebars guides: http://handlebarsjs.com/#iteration

@quaertym
Copy link
Contributor

@rjackson I have a problem that may be related to this. I have a linked list implementation in Ember and it is made enumerable using Enumerable Mixin interface as well. I want to use Ember each helper with this but it expects an Array. Can each helper be changed to work with Enumerable or should I implement my own helper for this case. I am currently using toArray after each update to the linked list which is not efficient.

@jlesquembre
Copy link

@rwjblue Is there any documentation where I can see the differences between standard handlebars and the ember version? I was getting the same error and finding the reason was frustrating, since according to the handlebars docs, it should work. And now I'm not sure anymore what features can I use.

@wagenet wagenet added Documentation and removed Bug labels Feb 17, 2015
@wagenet
Copy link
Member

wagenet commented Feb 17, 2015

I'm reopening this but as a documentation issue instead of a bug. It definitely seems like there's some confusion here about behavior that we should try to clear up.

@wagenet wagenet reopened this Feb 17, 2015
@mmun
Copy link
Member

mmun commented Feb 18, 2015

Object keys are stable on all modern browsers. Once diffing lands we'll lbe able to support this fairly simply. Presently it is difficult because we don't observe insertion/deletion of keys on objects.

@sandstrom
Copy link
Contributor

The ability to run {{#each}} on an Ember.Enumerable would be awesome :)

@stefanpenner
Copy link
Member

the {{each stuff now just blindly enumerates over forEachs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants