javascript - Angular.js $resource data processing -


i have server side rest api, can return jsonyfied data arbitrary structure. on client side have angular application.

resource defined:

module.factory('searchqueries', function ($resource){              return $resource('/instances/searches/:_id', {_id: '@_id'});  })                                                              

after try data api:

$scope.search_queries = searchqueries.query(null, function(args){     console.log('success: ', args);                                     (i in args) {                                                   }                                                                 });  

the client side receives data kinda structure:

{"2": "serfgserg", "3": "sdfgdfg", "4": "sdgdfhdfghfgh", "5": "sdgdfhdfghfgh"}

but! in success function of angular resource every symbol of data value of 1 element object.

[{"0":"s","1":"e","2":"r","3":"f","4":"g", e.t.c

why done? how prevent or use rightly?

edit:

if return array server:

res = json.dumps(["sdf", "asdf", "asdf"])                              return response(response=res, mimetype='application/json',         status=status) 

never mind have same result:

[{"0":"s"},{"0":"d"},{"0":"f"},{"0":"a"},{"0":"s"},{"0":"d"},{"0":"f"} // e.t.c      

this happends beacause query expects array of objects, not object - see the ngresource documentation:

'query': {method:'get', isarray:true}

expects like:

[{"name":"sdf"}, {"name":"asdf"}, {"name":"asd"}] 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -