【发布时间】:2016-04-24 21:51:05
【问题描述】:
我正在为我的移动应用程序使用 ion-autocomplete (https://github.com/guylabs/ion-autocomplete)。我需要在 ion-autocomplete 中设置选中的值,类似于下拉列表。
例如:自动完成显示所有国家,需要设置选择的国家。如果用户已经选择了印度国家,当他再次打开进行编辑时,它应该会显示已选择的印度,并且还会显示其他值。
<input ion-autocomplete type="text" readonly="readonly" class="ion-autocomplete"
placeholder="Enter the country to search"
items-method="getCountries(query)"
items-clicked-method="loadStates(callback)"
item-view-value-key="name"
item-value-key="id_country"
items-method-value-key="items"
max-selected-items="1"
autocomplete="off"
ng-model="registration.id_country"/>
$scope.countries =[{"id_country":"1","sortname":"AF","name":"Afghanistan"},
{"id_country":"2","sortname":"AL","name":"Albania"},
{"id_country":"3","sortname":"DZ","name":"Algeria"},
{"id_country":"4","sortname":"AS","name":"American Samoa"},
{"id_country":"5","sortname":"IN","name":"India"}];
$scope.getCountries = function(query) {
var returnValue = { items: [],selectedItems:[] };
$scope.countries.forEach(function(item){
if (item.name.indexOf(query) > -1 ){
returnValue.items.push(item);
}
else if (item.id_country.indexOf(query) > -1 ){
returnValue.items.push(item);
}
});
return returnValue;
}
在 ng-model registration.id_country 中,我传递了国家 ID。我尝试过类似地通过传递给 ng-model 来设置值,但没有成功。
【问题讨论】:
-
您解决了这个问题吗?如果成功,请分享解决方案,以便其他人使用。
标签: angularjs autocomplete ionic-framework