i working on angularjs application, accessing service , getting json data follows.
{ "repositoryfiledto":[ { "aclnode":"false", "createddate":"1433166794593", "filesize":"16208", "folder":"false", "hidden":"false", "id":"d4850a7e-17f7-4ee6-a3c5-125c26077da8", "lastmodifieddate":"1433166794593", "locale":"en", "localepropertiesmapentries":[ ], "locked":"false", "name":"accountinfo.prpt", "ownertype":"-1", "path":"/home/admin/accountinfo.prpt", "title":"accountinfo", "versionid":"1.0", "versioned":"true" }, { }, { }, { } ] }
from above array, need name property of each object , push them list.
here code, says undefined not function.
$scope.filtereddashboards = []; $scope.existingreportdetails = []; $scope.getreportdetails = function() { $http({ method: 'get', url: 'http://192.168.1.201/api/repo/files/%3ahome%3aadmin/children?showhidden=false&filter=*', // cache: $templatecache, headers: { 'access-control-allow-origin': '*', 'access-control-allow-methods': 'get, post, put, delete, options', 'access-control-allow-headers': 'content-type, x-requested-with', 'authorization': 'basic ywrtaw46cgfzc3dvcmq=' } }). success(function(data, status) { $scope.existingreportdetails = angular.tojson(data); $scope.filtereddashboards =$scope.existingreportdetails[0].repositoryfiledto ; console.log($scope.existingreportdetails); $scope.filtereddashboards.foreach(function(entry) { console.log(entry); }); $scope.existingreportdetails = $scope.existingreportdetails["1"].widgets; //alert("success"); }). error(function(data, status) { alert("request failed"); }); };
i need oput this,
$scope.reports = [ { name: "aoddetails", title: "#f00" }, { name: "accountinfo", title: "#0f0" } ]
have @ code on button click save function called , value stored in reports array.
<doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head> <body ng-app="myapp" data-ng-controller="homectrl"> <button ng-click="save()">save</button> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script> var app = angular.module('myapp',[]); app.controller('homectrl', function($scope){ $scope.data= { "repositoryfiledto":[ { "aclnode":"false", "createddate":"1433166794593", "filesize":"16208", "folder":"false", "hidden":"false", "id":"d4850a7e-17f7-4ee6-a3c5-125c26077da8", "lastmodifieddate":"1433166794593", "locale":"en", "localepropertiesmapentries":[ ], "locked":"false", "name":"accountinfo.prpt", "ownertype":"-1", "path":"/home/admin/accountinfo.prpt", "title":"accountinfo", "versionid":"1.0", "versioned":"true" }, { "aclnode":"false", "createddate":"1433166794593", "filesize":"16208", "folder":"false", "hidden":"false", "id":"d4850a7e-17f7-4ee6-a3c5-125c26077da8", "lastmodifieddate":"1433166794593", "locale":"en", "localepropertiesmapentries":[ ], "locked":"false", "name":"accountinfo1.prpt", "ownertype":"-1", "path":"/home/admin/accountinfo.prpt", "title":"accountinfo", "versionid":"1.0", "versioned":"true"}, { "aclnode":"false", "createddate":"1433166794593", "filesize":"16208", "folder":"false", "hidden":"false", "id":"d4850a7e-17f7-4ee6-a3c5-125c26077da8", "lastmodifieddate":"1433166794593", "locale":"en", "localepropertiesmapentries":[ ], "locked":"false", "name":"accountinfo2.prpt", "ownertype":"-1", "path":"/home/admin/accountinfo.prpt", "title":"accountinfo", "versionid":"1.0", "versioned":"true"}, { "aclnode":"false", "createddate":"1433166794593", "filesize":"16208", "folder":"false", "hidden":"false", "id":"d4850a7e-17f7-4ee6-a3c5-125c26077da8", "lastmodifieddate":"1433166794593", "locale":"en", "localepropertiesmapentries":[ ], "locked":"false", "name":"accountinfo3.prpt", "ownertype":"-1", "path":"/home/admin/accountinfo.prpt", "title":"accountinfo", "versionid":"1.0", "versioned":"true" } ] }; $scope.reports=[]; $scope.save=function() { for(var i=0; i<$scope.data.repositoryfiledto.length; i++) { var obj1={}; obj1.name=$scope.data.repositoryfiledto[i].name; obj1.title=$scope.data.repositoryfiledto[i].title; $scope.reports.push(obj1); } console.log($scope.reports); }; }); </script> </body> </html>
Comments
Post a Comment