代码: -
{ "Projects": [
{
"ProjectName" : "SmarTest",
"ProjectDescription" : "abc",
"ModuleDetails": [
{
"Maintitle":"Getting Started with IoT1"
},{
"Maintitle":"Getting Started with IoT2 "
}]
},
{
"ProjectName" : "SmarTest",
"ProjectDescription" : "abc",
"ModuleDetails": [
{
"Maintitle":"Getting Started with IoT3"
},{
"Maintitle":"Getting Started with IoT4"
}
]
}
]}
这是我的样本JSON,现在我希望使用 ng-repeat (IoT1入门和IoT3入门)从每个ModuleDetails
的第一个阵列获取主标题显示它。
我试过
<div ng-repeat="Module in Projects.ModuleDetails">
<div>{{Module[0].MainTitle}}</div>
</div>
答案 0 :(得分:1)
Check this plunkr, I think this is what you looking for
使用类似的内容:
<div ng-repeat="ob in data.Projects">
<div ng-repeat="a in ob.ModuleDetails">{{a.Maintitle}}</div>
</div>
答案 1 :(得分:0)
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="x in mdata.Projects">
<p>{{x.ModuleDetails[0].Maintitle}}</p>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$scope.mdata = {"Projects":[
{"ProjectName" : "SmarTest","ProjectDescription" : "abc","ModuleDetails":[{"Maintitle":"Getting Started with IoT1"},{"Maintitle":"Getting Started with IoT2"}]},
{"ProjectName" : "SmarTest","ProjectDescription" : "abc","ModuleDetails":[{"Maintitle":"Getting Started with IoT3"},{"Maintitle":"Getting Started with IoT4"}]}
]}
});
</script>
</body>
</html>