[英]Using ng-repeat
我正在尝试使用ng-repeat来显示所有threeDay.forecast.simpleforecast.forecastday.high.fahrenheit
,因为forecastday
是一个数组。 在这种情况下,我将如何使用ng-repeat
? 这是我的代码,仅显示Forecastday数组中第一条数据的华氏温度。
<body ng-app="ForecastApp">
<div class="main" ng-controller="MainController">
<p>{{ threeDay.forecast.simpleforecast.forecastday[0].high.fahrenheit }}</p>
</div>
</body>
您可以在这种情况下使用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元素。
假设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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.