我试图想出一种循环JSON对象并挑选符合特定条件的对象的方法。我需要用结果创建一个新的JSON。
我有一个树组件,节点中有复选框。我想只提取被检查的节点。已检查的节点可由"isSelected": true
我的JSON是 - https://pastebin.com/RHR2tAxZ
我是Angular的新手,之前没有处理过JSON循环。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
只需使用复选框
上的**foreign key (dept_name) references department(dept_name)
属性即可
isSelected
<强>样本强>
<input type="checkbox" ng-model="listitem.isSelected" >
var app = angular.module('myApp', []);
app.controller('AppCtrl', function($scope, $http) {
$scope.newList =[];
$scope.list=
[
{
"node": [
{
"node": [],
"pageName": "Upload Files",
"isSelected": false,
"node1": [],
"pagedefinitionId": 7
},
{
"node": [],
"pageName": "Download Files",
"isSelected": false,
"node1": [],
"pagedefinitionId": 8
}
],
"pageName": "Manage Files",
"isSelected": false,
"node1": [],
"pagedefinitionId": 4
},
{
"node": [],
"pageName": "Vendor Request",
"isSelected": false,
"node1": [
{
"isSelected": false,
"pageControlId": 89,
"elementIdentifier": "vendorRequest.add",
"pageDefinitionId": 355
},
{
"isSelected": false,
"pageControlId": 90,
"elementIdentifier": "vendorRequest.submitForApproval",
"pageDefinitionId": 355
},
{
"isSelected": false,
"pageControlId": 91,
"elementIdentifier": "vendorRequest.complete",
"pageDefinitionId": 355
}
],
"pagedefinitionId": 355
}
];
$scope.getselected = function(){
angular.forEach( $scope.list,function(key,value){
console.log(key);
if(key.isSelected){
$scope.newList.push(key);
}
});
}
});