【发布时间】:2019-09-18 05:13:42
【问题描述】:
我的代码有问题。
我正在使用自动完成文本视图。
首先,我从 API 获取所有国家/地区,带有 ID、名称等的简单 JSON。
{
"country_id": 249,
"name": "Aland Islands",
"short_name": "AX",
"company_id": "11E76234942280FBB13FFA163ECD2069"
},
我在自动完成中显示正确的数据名称。我要保存数据ID。
在 HTML 中:
<StackLayout backgroundColor="#66cdaa" padding="5">
<Label text="Select country"></Label>
<RadAutoCompleteTextView [items]="dataItems">
<SuggestionView tkAutoCompleteSuggestionView>
<ng-template tkSuggestionItemTemplate let-item="item">
<StackLayout orientation="vertical" padding="10">
<Label [text]="item.text"></Label>
</StackLayout>
</ng-template>
</SuggestionView>
</RadAutoCompleteTextView>
<Label text=""></Label>
<Button class="my-button" text="Sign Up" (tap)="register()"></Button>
</StackLayout>
我创建了一个DEMO
如何注册ID。比如我选择Aland Islands,注册的时候想注册country_id: 249。
【问题讨论】:
-
循环遍历国家集合,找到与所选名称匹配的对象并访问它的 id。
标签: angular autocomplete nativescript