JJJ
JJJ

Reputation: 2899

Ember Handlebars iterating over global javascript array

I have an array: var eventTypes = [{name: x, value: y}, ... {...}...]; and I'm trying to iterate over this with handlebars. I've tried

{{#each eventTypes
{{/each}}

but no luck. so, how can I iterate over a javascript array?

FIX: Made an Array controller that held the array within it.

Blocks.EventTypesController = Em.ArrayController.extend({
content: eventTypes // controller eventTypes = global eventTypes
});

Upvotes: 1

Views: 217

Answers (2)

Kingpin2k
Kingpin2k

Reputation: 47367

You need to attach that array to the controller which is backing the template, handlebars works within the scope of the controller, not the global scope.

App.SomeController = Em.Controller.extend({
  eventTypes: eventTypes // controller eventTypes = global eventTypes
});

Upvotes: 1

Kelly J Andrews
Kelly J Andrews

Reputation: 5111

You will need to use this to get to each object in the array as well.

{{#each eventTypes}}
    {{ this }}      
{{/each}}

Upvotes: 0

Related Questions