hodgesmr
hodgesmr

Reputation: 2785

Asynchronously update EmberJS Fixture Adapter

I have a table of links that I'm trying to pull from an external JSON file. Some simple HTML and Handlebars:

<table class="table">
  <thead>
    <tr><th>Links</th></tr>
  </thead>
  {{#each model}}
  <tr><td>
    <a target="_blank" {{bindAttr href="url"}}>{{title}}</a>
  </td></tr>
  {{/each}}
</table>

And from my app.js, I'm trying to load the JSON asynchronously into my Fixture Adapter:

var externalLinksJSON = [{
    id: 0
}];

$.getJSON('externalLinks.json', function(data) {
    externalLinksJSON = data;
})
.fail(function() { console.error("There was an error loading externalLinks.json"); });

App.ExternalLink.FIXTURES = externalLinksJSON;

Debugging the JavaScript shows that the externalLinksJSON variable is getting updated successfully, but EmberJS isn't updating the HTML with the newly fetch JSON. I'm trying to avoid blocking the browser with synchronous calls. Is there a way in EmberJS to bind the Fixtures so that it updates when the values change?

Upvotes: 0

Views: 176

Answers (1)

max
max

Reputation: 6069

I was under the impression the Fixtures adapter was for static testing data defined in the client's javascript, so my concern is whether it is designed to update after the app js has loaded.. Have you tried putting the Fixture data clientside to see whether that is the problem?

From the Ember site:

Fixtures are a way to put sample data into an application before connecting the application to long-term persistence.

Perhaps try using the REST adapter of Ember Data, or dealing with API calls by without Ember Data.

Upvotes: 1

Related Questions