Is it possible to pull a simple JSON array from the server and use it as a "constant lookup table" in an Ember application?
I have a rails controller that returns a simple array of strings: [ "item one", "item two", "item three", ...]
. I do not want them to to be full fledged Ember Models, nor do I want to represent them as an array of key:value pairs (ie, not [{name: "item one"}, {name: "item two"}, {name: "item three"}, ...]
)
How can I just pull the JSON array once, and reference that in my application?
To get started, I've tried just declaring a property on a controller that is then rendered in Handlebars by {{each}}
tags:
controller:
window.App.SimpleController = Ember.Controller.extend(
words: (() ->
Ember.$.getJSON("http://localhost:3000/dictionary")
).property()
)
template:
{{#each words}}
{{this}}
{{/each}}
Ember complains that this isn't an Array, but the jQuery promise object:
Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed {readyState: 1, getResponseHeader: ...
Which is confusing as well - I thought Ember handles promises as arrays?