Nativescript角度radListView`itemSelecting`示例

时间:2019-05-30 09:12:03

标签: nativescript nativescript-angular radlistview

有没有人知道一个链接,该链接显示了如何在Nativescript角度RadListView https://docs.nativescript.org/ns-ui-api-reference/classes/radlistview#itemselecting中实现date:"Y/m/d"的示例?

因为我找不到任何示例。谢谢。

1 个答案:

答案 0 :(得分:0)

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

找到解决方法