Tom
Tom

Reputation: 119

Ember JS transformation into Ember Data from using promises

I have a deep jSon structure to deal with so I currently implement promises directly into the Ember Model (not dependant on Ember Data).

This is shown as follows: -

return Ember.$.getJSON('/ProcessManager/manage type=submitters&action=getSubmitters').then(function(data) {

var submitters = [];

$.each(data, function(i, item) {
  $.each(item, function(i, item) {
    $.each(item, function(i, item) {
      Push each submitter into submitter array
        submitters.push(item);
      });
   });
});

return submitters;

});

An example complete jSON response from this URL is as follows: -

{"submitters":{"signsubmitter.jar":{"SignSubmitter":{"description":null,"name":"com.form.custom.submitters.SignSubmitter","jarName":"signsubmitter.jar"}},"custom-classes.jar":{"OutputDirSubmitter":{"description":"Writes the XML to a directory.","name":"com.form.custom.submitters.OutputDirSubmitter","jarName":"custom-classes.jar"},"XMLResponseSubmitter":{"description":"Returns the XML file to the client.","name":"com.form.custom.submitters.XMLResponseSubmitter","jarName":"custom-classes.jar"},"ChainProcess":{"description":"Chain the output file to another process.","name":"com.form.custom.submitters.ChainProcess","jarName":"custom-classes.jar"}}},"success":true}

I have read this URL: http://emberjs.com/guides/models/connecting-to-an-http-server/

I would like to know people's opinion on transitioning to Ember Data with this type of data.

Thank you.

Upvotes: 1

Views: 119

Answers (1)

TrevTheDev
TrevTheDev

Reputation: 2737

I've been using ember data with deeply nested record sets for a while now and I like it a lot. It should work just fine based on my understanding of the info you provided. Ideally you should be able to define the JSON in the format that ember expects see side loaded relationships here. If you get this right then most things are fine. Initially I spent many frustrated hours due to wrong casing and much of the doco is outdated and shows incorrect casing - this is something that you will have to work out for yourself - but if you get the odd meaningless error then casing may be the issue.

If you are unable to change the server JSON then you can simply override the RESTAdapter and RESTSerializer to meet requirements. This is also simple and works.

Ember data works well for me and does what I need it to.

Ember is designed to work with promises and to load deeply nested record sets the order in which these promises resolve can be very important. There is enough info here on SO on how this can be achieved.

Upvotes: 1

Related Questions