我正在尝试使用ng-repeat来显示所有threeDay.forecast.simpleforecast.forecastday.high.fahrenheit
,因为forecastday
是一个数组。在这种情况下我如何使用ng-repeat
?这是我的代码,只显示预测日数组中第一个数据的fahrenheit值。
<body ng-app="ForecastApp">
<div class="main" ng-controller="MainController">
<p>{{ threeDay.forecast.simpleforecast.forecastday[0].high.fahrenheit }}</p>
</div>
</body>
答案 0 :(得分:2)
你可以像你这样使用ng-repeat:
<body ng-app="ForecastApp">
<div class="main" ng-controller="MainController">
<p ng-repeat="forecastday in threeDay.forecast.simpleforecast.forecastday">
{{ forecastday.high.fahrenheit }}
</p>
</div>
</body>
只需遍历所有的threeDay.forecast.simpleforecast.forecastday表,并显示其中的每个high.fahrenheit元素。
答案 1 :(得分:0)
假设threeDay.forecast.simpleforecast.forecastda
是一个集合/数组,并且该数组中的每个项目都具有high
属性,该属性又具有fahrenheit
属性
<body ng-app="ForecastApp">
<div class="main" ng-controller="MainController">
<p ng-repeat="f in threeDay.forecast.simpleforecast.forecastday">
{{f.high.fahrenheit}}
</p>
</div>
</body>