I'm trying to pass some filters to my getList method of Restangular.
In my app I have this:
var filters = Filters.get();
var query = {};
for (var i in filters) {
query['filters['+i+']'] = filters[i];
}
query['userId'] = userId;
Restangular.all('pets').getList(query).then(...
And in the server side (Node + ExpressJS) I have this:
var filters = req.query.filters;
for(var i in filters){
console.log(filters[i]);
}
that is consoling objects like this:
{"category":"Tipo","options":[{"name":"Perros","realName":"perro","checked":true},{"name":"Gatos","realName":"gato","checked":true}]}
But, I don't know why when I try console.log(filters[i].category); is not consoling Tipo
Can anyone see something that I am not seeing, or has a better way to do this?
Thanks!
Finally it was a silly mistake! I have to parse the response like this: JSON.parse(filters[i]);