1

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.

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I knew it had to be something I didn't yet grasp. Suffering through the learning process... trying to keep my classic past out of my mind. Man what a struggle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.