I'm getting a strange behaviour with AngularJS's $http and not really understanding how transformResponse works (the docs are a bit light on this one).
WebAssets.get = function () {
return $http.get('/api/webassets/list', {
transformResponse: [function (data, headersGetter) {
// not sure what to do here?!
return data;
}].concat($http.defaults.transformResponse) // presume this isn't needed, added for clarity
}).then(function (response) {
return new WebAssets(response.data);
});
};
The api returns an array of objects:
[{"webasset_name": "...", "application_id": "...", "etc": "..."}, ... ]
But when transformResponse has done it's evil business the data has transformed into an indexed object:
{"0":{"webasset_name":"...","application_id":"...", "etc": "..."}, "1":....}
I want to keep the original data structure (an array of objects).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…