Can a simple JSON array be retrieved from the server and used as a constant lookup table in an Ember application?
I have a Rails controller that sends back a basic array of strings:
[ "item one", "item two", "item three", ...]
. I do not want these to be full Ember Models, nor do I want them represented as key:value pairs (so not like this: [{name: "item one"}, {name: "item two"}, {name: "item three"}, ...]
)
How can I fetch the JSON array once and then reference it in my application?
For starters, I attempted to define a property on a controller that is then displayed in Handlebars using {{each}}
tags:
controller:
window.App.SimpleController = Ember.Controller.extend(
words: (() ->
Ember.$.getJSON("http://localhost:3000/dictionary")
).property()
)
template:
{{#each words}}
{{this}}
{{/each}}
Ember is showing an error that it's not an Array, but a jQuery promise object:
Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed {readyState: 1, getResponseHeader: ...
This is also confusing - I thought Ember could handle promises as arrays?