问问题
5144 次
2 回答
1
我认为您正在寻找与您指出的 react-native-picker-select 类似的nativescript-drop-down 。
于 2019-01-07T18:13:29.713 回答
0
我一直在寻找相同的解决方案,但找不到,所以我创建了自己的解决方案。我在这里为你附上了一个样本。
您可以拥有一个 textField/Label 和 onTab,您可以显示 ListPicker,就像Select
HTML 中的行为一样,它将仅使用本机(平台特定)组件。
在您的 HTML 中
<StackLayout orientation="vertical" width="210" height="210" backgroundColor="lightgray">
<Label text="Country" width="70" height="50" backgroundColor="red"></Label>
<TextField [(ngModel)]="textFieldValue" hint="Choose countty..." editable="false" (tap)="showHideField('country')"></TextField>
</StackLayout>
<StackLayout orientation="vertical" width="100%" height="210" *ngIf="showCountryPicker" backgroundColor="lightgray">
<ListPicker [items]="listPickerCountries" (selectedIndexChange)="selectedCountyChanged($event)"></ListPicker>
</StackLayout>
和你的 .ts 文件
showCountryPicker = false;
listPickerCountries: Array < string > = ["Australia", "Belgium", "Bulgaria", "Canada", "Switzerland",
"China", "Czech Republic", "Germany", "Spain", "Ethiopia", "Croatia", "Hungary",
"Italy", "Jamaica", "Romania", "Russia", "United States"
];
showHideField() {
this.showCountryPicker = true;
}
selectedCountyChanged(args) {
const picker = < ListPicker > args.object;
this.showCountryPicker = false;
this.textFieldValue = this.listPickerCountries[picker.selectedIndex];
}
于 2019-01-09T06:13:33.650 回答