大家好,我正在使用AngularJS创建一个应用程序Web。
我想在我的选择中显示城市02作为默认选择,并删除像city_02这样的两个单词下划线之间的下划线,比如显示城市,城市02,城市03而不是城市,city_02,city_03我的选择
<select ng-model="selectedCity" ng-options="x for (x, y) in cities">
</select>
这是我的脚本js:
$scope.cities = {
city : [
{id:'c01' , name:'name1', price:15},
{id:'c02' , name:'name2', price:18},
{id:'c03' , name:'name3', price:11},
],
city_02 : [
{id:'cc01' , name:'name11', price:10},
{id:'cc02' , name:'name22', price:14},
{id:'cc03' , name:'name33', price:11},
],
city_03 : [
{id:'ccc01' , name:'name111', price:19},
{id:'ccc02' , name:'name222', price:18},
{id:'ccc03' , name:'name333', price:10},
]
};
任何人都有想法。感谢
答案 0 :(得分:1)
要将城市02显示为默认选定值,只需设置$scope.selectedCity = 'city_02'
。
要在您的选择中显示时消除下划线,请添加以下过滤器:
.filter('cityFilter', function() {
return function(city) {
return city.replace('_', ' ');
}
})
然后在你的ng-options
中使用它:
ng-options="x as (x | cityFilter) for (x, y) in cities"