-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_json.html
More file actions
37 lines (36 loc) · 1.07 KB
/
parse_json.html
File metadata and controls
37 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div>{{bookmarks}}</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.bookmarks = [];
$http.get("https://api.myjson.com/bins/orke1")
.then(function(response) {
flatten(response.data.roots.bookmark_bar);
});
function flatten(array, parentID) {
var bookmark = {};
if(array.type === 'folder' || array.type === 'url') {
bookmark.id = array.id;
bookmark.name = array.name;
bookmark.type = array.type;
bookmark.date_added = array.date_added;
bookmark.date_modified = array.date_modified;
bookmark.parentId = parentID;
$scope.bookmarks.push(bookmark);
if(array.children && array.children.length > 0) {
for (var i = 0; i < array.children.length; i++) {
flatten(array.children[i],array.id);
}
}
}
}
});
</script>
</body>
</html>