Html 使用ng repeat从JSon获取数据并显示
代码:- 这是我的JSON示例,现在我想使用ng repeat(开始使用IoT1和开始使用IoT3)从每个Html 使用ng repeat从JSon获取数据并显示,html,angularjs,Html,Angularjs,代码:- 这是我的JSON示例,现在我想使用ng repeat(开始使用IoT1和开始使用IoT3)从每个ModuleDetails的第一个数组中获取主标题并显示它 我试过了 {{模块[0].maintTitle} 使用类似于: { "Projects": [ { "ProjectName" : "SmarTest", "ProjectDescription" : "abc", "ModuleDetails": [ { "Ma
ModuleDetails
的第一个数组中获取主标题并显示它
我试过了
{{模块[0].maintTitle}
使用类似于:
{ "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"
}
]
}
]}
{{a.Maintitle}}
{x.ModuleDetails[0].Maintitle}
var-app=angular.module('myApp',[]);
app.controller('myCtrl',函数($scope,$http){
$scope.mdata={“项目”:[
{“ProjectName”:“SmarTest”,“ProjectDescription”:“abc”,“ModuleDetails”:[{“Maintitle”:“IoT1入门”},{“Maintitle”:“IoT2入门”}]},
{“ProjectName”:“SmarTest”,“ProjectDescription”:“abc”,“ModuleDetails”:[{“Maintitle”:“IoT3入门”},{“Maintitle”:“IoT4入门”}]}
]}
});
编译代码时您看到的输出可能重复?此问题目前没有足够的信息可供我们帮助您。请详细说明您代码的当前行为。因此,我只希望开始使用IoT1和IoT3displayed@user9664067当前位置如果你得到了你想要的答案,请写下解释。
<div ng-repeat="ob in data.Projects">
<div ng-repeat="a in ob.ModuleDetails">{{a.Maintitle}}</div>
</div>
<!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>