我正在尝试在每个州代码下创建一个包含城市的列表。 我有一系列像这样的州:
states = [{ state:"AK",
Cities:[{cityName:"Anchorage",
cityCode:"ANC"},
{cityName:"Barrow",
cityCode: "BRW"}]
},
{
state:"AL",
Cities:[{cityName:"Anniston",
cityCode:"ANB"},
{cityName:"Birhimgham",
cityCode: "BHM"}]
}]
现在,我想按状态显示城市列表,其中州是列表标题。
<ion-content>
<ion-list>
<ion-item class="item-divider" ng-repeat="state in states"> {{state.state}}
<ion-list>
<ion-item ng-repeat="city in state.Cities">
{{city.CityName}}
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-content>
如何实现目标?
答案 0 :(得分:1)
希望这可以解决您的问题:
<ion-content>
<ion-list ng-repeat="state in states">
<ion-list-header>{{state.state}}</ion-list-header>
<ion-item ng-repeat="city in state.Cities">{{city.CityName}}</ion-item>
</ion-list>
</ion-content>
或者确切地说:
<ion-content>
<ion-item-group ng-repeat="state in states">
<ion-item-divider color="light">{{state.state}}</ion-item-divider>
<ion-item ng-repeat="city in state.Cities">{{city.CityName}}</ion-item>
</ion-item-group>
</ion-content>