Nativescript angular radListView `itemSelecting` 示例
Nativescript angular radListView `itemSelecting` example
有没有人知道 link,它展示了如何在 Nativescript angular RadListView
https://docs.nativescript.org/ns-ui-api-reference/classes/radlistview#itemselecting 中实现 itemSelecting
的示例?
因为我找不到任何例子。谢谢。
HTML
<RadListView class="list-group" [items]="countries" selectionBehavior="Press"
multipleSelection="true" (itemSelecting)="onItemSelecting($event)"
(itemDeselecting)="onItemSelecting($event)">
<ng-template let-country="item">
<FlexboxLayout flexDirection="row" class="list-group-item">
<Image [src]="country.imageSrc" class="thumb img-circle"></Image>
<Label [text]="country.name" class="list-group-item-heading"
verticalAlignment="center" style="width: 60%"></Label>
</FlexboxLayout>
</ng-template>
</RadListView>
TS
import { ListViewEventData } from "nativescript-ui-listview"
import { Component } from "@angular/core";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ["./home.component.css"]
})
export class HomeComponent {
countries: { name: string, imageSrc: string }[] = [
{ name: "Australia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/au.png" },
{ name: "Belgium", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/be.png" },
{ name: "Bulgaria", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/bg.png" },
{ name: "Canada", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ca.png" },
{ name: "Switzerland", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ch.png" },
{ name: "China", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/cn.png" },
{ name: "Czech Republic", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/cz.png" },
{ name: "Germany", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/de.png" },
{ name: "Spain", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/es.png" },
{ name: "Ethiopia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/et.png" },
{ name: "Croatia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/hr.png" },
{ name: "Hungary", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/hu.png" },
{ name: "Italy", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/it.png" },
{ name: "Jamaica", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/jm.png" },
{ name: "Romania", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ro.png" },
{ name: "Russia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ru.png" },
{ name: "United States", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/us.png" },
];
onItemSelecting(args: ListViewEventData): void {
console.log(args.view.bindingContext.name);
args.returnValue = args.index > 5;
}
}
注意: 它似乎有问题,至少在 Android 上是这样。第二次点击未能触发 itemSelecting
事件并将该项目标记为已选中。可以在 nativescript-ui-feedback/issues/181
找到解决方法
有没有人知道 link,它展示了如何在 Nativescript angular RadListView
https://docs.nativescript.org/ns-ui-api-reference/classes/radlistview#itemselecting 中实现 itemSelecting
的示例?
因为我找不到任何例子。谢谢。
HTML
<RadListView class="list-group" [items]="countries" selectionBehavior="Press"
multipleSelection="true" (itemSelecting)="onItemSelecting($event)"
(itemDeselecting)="onItemSelecting($event)">
<ng-template let-country="item">
<FlexboxLayout flexDirection="row" class="list-group-item">
<Image [src]="country.imageSrc" class="thumb img-circle"></Image>
<Label [text]="country.name" class="list-group-item-heading"
verticalAlignment="center" style="width: 60%"></Label>
</FlexboxLayout>
</ng-template>
</RadListView>
TS
import { ListViewEventData } from "nativescript-ui-listview"
import { Component } from "@angular/core";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ["./home.component.css"]
})
export class HomeComponent {
countries: { name: string, imageSrc: string }[] = [
{ name: "Australia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/au.png" },
{ name: "Belgium", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/be.png" },
{ name: "Bulgaria", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/bg.png" },
{ name: "Canada", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ca.png" },
{ name: "Switzerland", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ch.png" },
{ name: "China", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/cn.png" },
{ name: "Czech Republic", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/cz.png" },
{ name: "Germany", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/de.png" },
{ name: "Spain", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/es.png" },
{ name: "Ethiopia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/et.png" },
{ name: "Croatia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/hr.png" },
{ name: "Hungary", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/hu.png" },
{ name: "Italy", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/it.png" },
{ name: "Jamaica", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/jm.png" },
{ name: "Romania", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ro.png" },
{ name: "Russia", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/ru.png" },
{ name: "United States", imageSrc: "https://play.nativescript.org/dist/assets/img/flags/us.png" },
];
onItemSelecting(args: ListViewEventData): void {
console.log(args.view.bindingContext.name);
args.returnValue = args.index > 5;
}
}
注意: 它似乎有问题,至少在 Android 上是这样。第二次点击未能触发 itemSelecting
事件并将该项目标记为已选中。可以在 nativescript-ui-feedback/issues/181