我想使用angular2
基于某些条件查询JSON数据我的json是:
{
"logsArray":[
{
"Id": "1",
"ProjectName": "Project01",
"ModuleName": "Module01",
"MethodName": "Method01",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "2",
"ProjectName": "Project02",
"ModuleName": "Module01",
"MethodName": "Method03",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "3",
"ProjectName": "Project03",
"ModuleName": "Module05",
"MethodName": "Method01",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "4",
"ProjectName": "Project01",
"ModuleName": "Module07",
"MethodName": "Method01",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "5",
"ProjectName": "Project03",
"ModuleName": "Module01",
"MethodName": "Method10",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "6",
"ProjectName": "Project06",
"ModuleName": "Module01",
"MethodName": "Method05",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "7",
"ProjectName": "Project03",
"ModuleName": "Module03",
"MethodName": "Method07",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
},
{
"Id": "8",
"ProjectName": "Project04",
"ModuleName": "Module03",
"MethodName": "Method05",
"Message": "MessageMessage",
"MessageDetails": "MessageDetailsMessageDetails",
"LogType": "LogType",
"CreatedDate": "Fri May 04 2012 01:17:07 GMT-0700 (PDT)",
"CreatedBy": "User01"
}
]
}
我希望根据某些条件获得特定属性,例如
PojectName = Project03
区分ModuleName,其中ModuleName = Module02&& MethodName = Method01
不同的方法名称ProjectName = Project01
答案 0 :(得分:0)
你签出了Angular2 Json API library吗?
完成设置后,它看起来像这样:
this.datastore.findRecord(logsArray, '1').subscribe(
(post: logsArray) => console.log(post)
);
答案 1 :(得分:0)
使用angular 2 http get方法在角度服务中获取json数据。
this.http.get(./filename.json)
.map((res:Response)=>res.json())
.subscribe(data=>this.temp=data.logsArray.filter())
或者您可以使用Observables的过滤方法。
答案 2 :(得分:-1)
你的意思是这样吗?
var nameSpace = angular.module("GuitarApp", []);
nameSpace.controller("GuitarFunction", ['$scope','$http', function($scope, $http)
{
$http.get('js/data.json').success (function(data){ // json call
$scope.guitarVariable = data;
});
}]
);