hal9000
hal9000

Reputation: 852

EmberJS error while processing route

I am grabbing json data from a service that I cannot change. I am trying to load this data into an Ember.ArrayController.

Error I am dealing with:

Error while processing route: profiles Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object

data format looks like this

var testData =
{
    "CustomerProfilesResult": [
        { "DOB": "10\/23\/1969 12:00:00 AM", "DateEnrolled": "7\/10\/2014 12:00:00 AM", "FirstName": "Rob", "LastName": "Weiner", "ProfileId": 1 }, 
        { "DOB": "10\/23\/1979 12:00:00 AM", "DateEnrolled": "10\/3\/2014 12:00:00 AM", "FirstName": "Repub", "LastName": "Smitty", "ProfileId": 1 }, 
        { "DOB": "10\/23\/1978 12:00:00 AM", "DateEnrolled": "10\/17\/2014 12:00:00 AM", "FirstName": "Democrat", "LastName": "Johnson", "ProfileId": 1 }, 
        { "DOB": "10\/23\/1996 12:00:00 AM", "DateEnrolled": "10\/18\/2014 12:00:00 AM", "FirstName": "Itchy", "LastName": "Digger", "ProfileId": 1 }]
};

This should be simple... but Ember only wants it when its not wrapped in the CustomerProfilesResult. I've tried returning

        return Ember.$.getJSON(getProfiles)
        .success(function(data){
            return data;
        }).error(function(){
            alert('error happened... should have caught this.')
        });

and

  return Ember.$.getJSON(getProfiles)
        .success(function(data){
            return data.CustomerProfilesResult;
        }).error(function(){
            alert('error happened... should have caught this.')
        });

both of which fail with

but during testing I have returned

return testData.CustomerProfilesResult;

just fine so its confusing. I know its something stupid I'm missing... help if you can.

Upvotes: 1

Views: 865

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

success doesn't care about the value you return to it, so it isn't returned to the model hook when the promise is resolved. The original json data is sent to both the success call and the then portion of the promise.

return Ember.$.getJSON(getProfiles)
.then(function(data){
   return data.CustomerProfilesResult;
});

Example: http://emberjs.jsbin.com/hafaj/edit

Upvotes: 1

Related Questions