根据两个不同的数据用otpgroup创建select
Create select with otpgroup based on two different data
朋友们好,两个数据在一个 JSON 文件中,我需要根据国家/地区字段创建 Select 选项并根据位置字段显示数据
"countries": [
{
"id": "75",
"country": "France"
},
{
"id": "82",
"country": "Germany"
},
{
"id": "208",
"country": "Switzerland"
},
{
"id": "226",
"country": "United Kingdom"
},
{
"id": "227",
"country": "United States"
}
],
location": [
{
"id": "49",
"name": "Aberdeen",
"country_id": "226",
"country": "United Kingdom"
},
{
"id": "52",
"name": "All Cities",
"country_id": "226",
"country": "United Kingdom"
},
{
"id": "51",
"name": "All Cities",
"country_id": "82",
"country": "Germany"
},
{
"id": "50",
"name": "All Cities",
"country_id": "227",
"country": "United States"
}
{
"id": "31",
"name": "San Jose",
"country_id": "227",
"country": "United States"
},
{
"id": "42",
"name": "Seattle",
"country_id": "227",
"country": "United States"
},
{
"id": "18",
"name": "Stuttgart",
"country_id": "82",
"country": "Germany"
},
{
"id": "41",
"name": "Washington DC",
"country_id": "227",
"country": "United States"
}
],
HTML 文件
<select ng-model="location">
<optgroup ng-repeat="data in location" label="{{data.country}}">
<option ng-repeat="item in data" value="{{data.country}}::{{item.name}}">{{item.name}}</option>
</optgroup>
</select>
我需要显示我的数据:
我尝试了上面的代码,但没有成功。请帮忙
无需使用不同的数组,您也可以仅使用位置数组来实现,如下所示
<select ng-model="location" ng-options="option.name as option.name group by option.country for option in locations"></select>
朋友们好,两个数据在一个 JSON 文件中,我需要根据国家/地区字段创建 Select 选项并根据位置字段显示数据
"countries": [
{
"id": "75",
"country": "France"
},
{
"id": "82",
"country": "Germany"
},
{
"id": "208",
"country": "Switzerland"
},
{
"id": "226",
"country": "United Kingdom"
},
{
"id": "227",
"country": "United States"
}
],
location": [
{
"id": "49",
"name": "Aberdeen",
"country_id": "226",
"country": "United Kingdom"
},
{
"id": "52",
"name": "All Cities",
"country_id": "226",
"country": "United Kingdom"
},
{
"id": "51",
"name": "All Cities",
"country_id": "82",
"country": "Germany"
},
{
"id": "50",
"name": "All Cities",
"country_id": "227",
"country": "United States"
}
{
"id": "31",
"name": "San Jose",
"country_id": "227",
"country": "United States"
},
{
"id": "42",
"name": "Seattle",
"country_id": "227",
"country": "United States"
},
{
"id": "18",
"name": "Stuttgart",
"country_id": "82",
"country": "Germany"
},
{
"id": "41",
"name": "Washington DC",
"country_id": "227",
"country": "United States"
}
],
HTML 文件
<select ng-model="location">
<optgroup ng-repeat="data in location" label="{{data.country}}">
<option ng-repeat="item in data" value="{{data.country}}::{{item.name}}">{{item.name}}</option>
</optgroup>
</select>
我需要显示我的数据:
我尝试了上面的代码,但没有成功。请帮忙
无需使用不同的数组,您也可以仅使用位置数组来实现,如下所示
<select ng-model="location" ng-options="option.name as option.name group by option.country for option in locations"></select>