angularjs服务:获取JSON子记录字段以导入到当前的开放阵列记录中。
我有一个带有"服务"的JSON文件(ID,name(Services.json,我需要浏览它们,但是当我在每项服务中,我需要打开子记录(welding.json(并获取字段(标题(并将其添加到当前记录中。
注意:我的项目是CLI类型。
services.json
[
{
"id": 1,
"name": "welding"
},
{
"id": 2,
"name": "carpentry"
},
{
"id": 3,
"name": "mechanic"
}
]
= sub-records =
焊接
{
"category": "labor",
"title": "Arc Welding",
"description": "",
"experience": "20+ Years",
"details": ""
}
期望:
{
"id": 1,
"name": "welding",
"title": "Arc Welding"
}
尝试此
angular.forEach($scope.services, function (value, key) {
if(value.name == 'welding'){
$http.get('welding.json').then(function (response) {
$scope.welding = response;
})
$scope.services.title=$scope.welding.title;
}});