我在我的项目中使用ion-autocomplete
,这就是我想要做的事情:
这是输入字段:
<label class="item item-input item-stacked-label">
<span class="input-label">Multiple select autocomplete</span>
<input ion-autocomplete type="text" readonly="readonly"
class="ion-autocomplete" autocomplete="on"
ng-model="model"
item-value-key="lastname"
item-view-value-key="firstname"
items-method="getTestItems(query)"
items-method-value-key="items"
placeholder="Enter test query ..."
items-clicked-method="itemsClicked(callback)"
items-removed-method="itemsRemoved(callback)" />
</label>
这是控制器:
$scope.getTestItems =function (query) {
if (query) {
return {
items: [
{"matricule":"5324", "id":270, "lastname":"IZIKKI", "firstname":"SAID"},
{"matricule":"5505", "id":271, "lastname":"BOUKASIM", "firstname":"EL MAACHI"},
{"matricule":"5505", "id":272, "lastname":"BELMOUMENE", "firstname":"MHAMED"}
]
};
}
return {
items: []
};
};
我想做的是,我想通过matricule进行搜索。换句话说,当我输入5324
时,我想要姓氏,并且与该matricule关联的名字出现在列表中。当我点击 done 时,我希望它出现在模型中。
我怎样才能实现这一目标?