[英]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.