我的json如下所示
var content = [{
"DocList": [
{
"Events": [
{
"CategoryName": "PressStatements",
"DisplayName": "Press Statements",
"ID": 9
},
{
"CategoryName": "Reports",
"DisplayName": "Reports",
"ID": 10
}
],
"Heading": "News 2",
"PageID": 23,
"Date": "\/Date(1454537792000)\/"
},
{
"Events": [
{
"CategoryName": "Research",
"DisplayName": "Research",
"ID": 6
}
],
"Heading": "Heading",
"PageID": 20,
"Date": "\/Date(1437417792000)\/"
}
]}
];
$scope.data=content;
$scope.filterItems = function(g) {
//console.log('filterItems is run');
var ret = $filter('filter')(g.NewsList,"");
//g.filteredItemCount = ret.length
return ret
};
想要为Events创建一个下拉列表,它将显示CategoryName的select选项。并根据从事件中选择CategoryName来过滤掉详细信息。下面的代码只是向我展示了每个对象的第一个元素。就像我将选择选项作为PressStatements和Research,但我也希望报告在下拉列表中。
<select ><option ng-repeat="item1 in (filtered = filterItems(d))"> {{item1.Events[0].DisplayName}}</option></select>
答案 0 :(得分:0)
最后,我在select标签
中获得了所有选项$scope.abms = [];
console.log(news[0].NewsList);
angular.forEach(news[0].NewsList, function(newsItems, index) {
angular.forEach(newsItems.CategoryList, function(category, index){
$scope.abms.push(category.DisplayName);
});
});