Quantcast
Channel: User Sneaky Toes - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by Sneaky Toes for AngularJs, Django RESTful and Restangular: Consuming an array of hyperlinks

$
0
0

I have not found a solution which performs a get() on all nested urls independently without doing it explicitly in the controller.

So for these twice nested jsons, I created three different objects rather than one full cabinet object. Restangular than can use its put and patch methods on the objects returned.

Then I iterate through each folder in the cabinet, and in turn each file in the folder to get all my objects into the view.

If anybody has a better way let me know!

vm.cabinet = {};vm.folders = [];vm.files = {}Cabinet.get(id).then(cabinetSuccessFn, errorFn);function cabinetSuccessFn(response) {        vm.cabinet = response;        vm.cabinet.folders.map(function(folder) {          return Folder.get(parseInt(folder.substr(folder.lastIndexOf('/', folder.length - 2) + 1).slice(0, -1))).then(folderSuccessFn, errorFn);        });        vm.loading = false;      }function folderSuccessFn(response) {        vm.folders.push(response);        vm.files[response.id] = [];        response.files.map(function(file) {          return Files.get(parseInt(file.substr(file.lastIndexOf('/', file.length - 2) + 1).slice(0, -1))).then(fileSuccessFn, errorFn);        });      }function fileSuccessFn(response) {        vm.filess[response.folder.substr(response.folder.lastIndexOf('/', response.folder.length - 2) + 1).slice(0, -1)].push(response);      }function errorFn(response) {    $log.error('unable to load resource');    $log.error(response);}

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>