Cannot see the Restangular response data set in my chrome developer tools... is it bc my JSON contains nested JSON?

StackOverflow https://stackoverflow.com/questions/17275977

  •  01-06-2022
  •  | 
  •  

Question

I'm currently trying to get a basic RESTful service up that pulls my JSON objects from MongoLab rather than the file-based implementation which I had working in my sandbox. Each of my JSON objects contain a child array (their predecessor IDs):

{title: 'xxyy1', course_id: '10004', semester_hours: 3, detail: 'coursename1', predecessors: ['10001']},
{title: 'xxyy2', course_id: '10005', semester_hours: 3, detail: 'coursename2', predecessors: ['10001','10003','10004']},
{title: 'xxyy3', course_id: '10006', semester_hours: 3, detail: 'coursename3', predecessors: ['10001','10003','10004']},
{title: 'xxyy4', course_id: '10007', semester_hours: 3, detail: 'coursename4', predecessors: ['10004','10006']}

This works perfectly fine when stringing this up into angularJS, by simply pulling the course.title, course.course_id, etc. into an ng-repeat. Even the predecessors easily is managed by constructing it as direct JSON.

<span class="predecessors">{{course.predecessors | json}}</span>

However, when trying to pull this same dataset from MongoLab using Restangular as my resource provider, I'm unable to see any data responded in the view... actually, I cannot see any data anywhere. Using Chrome's dev tools, all I see is the following:

![Restangular Response]: http://imgur.com/w8qE96K.jpg

Am I missing something here? My Mongo implementation is as follows:

  RestangularProvider.setRestangularFields({
    id: 'course_id'
  });


  RestangularProvider.setListTypeIsArray(false);

  RestangularProvider.setResponseExtractor(function(response, operation, what, url) {

    var newResponse;
    if (operation === "getList" && what === "availableCourses") {

        console.log(response);

        newResponse = response.data.title;
        newResponse.course_id = response.data.course_id;
        newResponse.semester_hours = response.data.semester_hours;
        newResponse.detail = response.data.detail;
        newResponse.predecessors = response.data.predecessors;
    } else {
        newResponse = response.data;
    }
    return newResponse;
  });
Was it helpful?

Solution

I'm the creator of Restangular.

So, when you're doing a getList, Restangular expects to get an Array as the response. In your case, when you're getting a list and the path is availableCourses, you're returning a string (the title) which has properties. So you're creating a "special" string with properties, it's not really common, nor compatible with Restangular.

If you want to get the list of all available courses, you need to return an array as the new response. So, what's the exact response from the server when you do the getList? If you giv eme that, I'll be able to help you easier on how to create this response extarctor.

Also take a look to this MongoLab example :), maybe It'll help you.

http://plnkr.co/edit/d6yDka?p=preview

Bests!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top