vit*_*lym 12 arrays json angularjs
我需要迭代嵌套的json数组,看起来像那样
[
{
"title": "EPAM",
"technologies": [
"PHP",
".net",
"Java",
"Mobile",
"Objective-C",
"Python",
"Ruby"
],
"location": "Belarus",
"city": "Minsk"
},
{
"title": "Parallels",
"technologies": [
"PHP",
"Java",
"C++",
"iOS Development",
"C#",
"Ember.js"
],
"location": "Russia",
"city": "Moscow"
}
]
Run Code Online (Sandbox Code Playgroud)
我想要的是遍历每个公司的技术列表,然后返回一个唯一值列表.但是,我无法访问控制器中公司阵列中的单个公司.到目前为止看起来像这样
var app = angular.module('app', []);
app.controller('CompaniesController', ['$scope', '$http',
function($scope, $http) {
$http.get('json/companies.json').success(function(data) {
$scope.companies = data; // get data from json
$scope.techStack = []
$scope.companies = data.query(function(companies) {
console.log(companies); //I expected to see data here
});
});
}
]);
Run Code Online (Sandbox Code Playgroud)
显然我做错了什么.
use*_*587 28
使用angular's forEach:
var app = angular.module('app', []);
app.controller('CompaniesController', ['$scope', '$http',
function($scope, $http) {
$http.get('json/companies.json').success(function(data) {
$scope.companies = data; // get data from json
angular.forEach($scope.companies, function(item){
console.log(item.technologies);
})
});
});
}
]);
Run Code Online (Sandbox Code Playgroud)
如果您只需要在UI上显示嵌套数组,您可以直接在视图中执行此操作,例如
<tr ng-repeat="i in Items">
<td valign="top">{{i.Value}}</td>
<td valign="top">
<table>
<tr ng-repeat="c in i.Children">
<td>{{c.Value}}</td>
</tr>
</table>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)