【问题标题】:accessing RadListView from button inside ng-template button nativescript angular从ng-template按钮nativescript angular内的按钮访问RadListView
【发布时间】:2019-09-11 18:28:36
【问题描述】:

点击按钮时如何访问父列表视图(RadListView)索引

需要从 ng-template 中的按钮访问 listview indext,但无法获得任何指导'

我尝试了 args.object.parent 但没有运气。

<RadListView row="0" [items]="dataItems" selectionBehavior="Press"
     (itemDeselected)="onItemDeselected($event)" (itemDeselected)="onItemDeselected($event)"
     multipleSelection="true" *ngIf="!restoClose" >
            <ng-template let-dish="item" let-i="index"  >
                <GridLayout orientation="horizontal" class="list-group-item m-5 "
                    rows="auto" columns="auto,*,auto">
                    <Image col="0" row="0" [src]="dish.image" height="30"
                        width="30"></Image>
                    <StackLayout col="1" row="0" marginLeft="15">
                        <Label marginTop="5" paddingRight="5" [text]="dish.name"
                            class="list-group-item-heading"
                            color="#333333"></Label>
                        <Label marginTop="5" [text]="dish.description" color="#999999" textWrap="true"></Label>
                    </StackLayout>
                    <Button col="2" width="80" horizontalAlignment="right" class="btn btn-primary btn-rounded-lg" 
                    text="{{ dish.price | number:'1.2' }}" (tap)="onItemSelecting($event)"></Button>
                </GridLayout>
            </ng-template>
    </RadListView>

//这是组件

public onItemSelecting(args) {
    console.log('want to access from here', args.object.parent);
    const listview = args.object.parent as RadListView;
    const selectedItems = listview.getSelectedItems() as Array<TfmenuItem>;
    let selectedTitles = "Selecting item: ";
    for (let i = 0; i < selectedItems.length; i++) {
        selectedTitles += selectedItems[i] ? selectedItems[i].name : "";

        if (i < selectedItems.length - 1) {
            selectedTitles += ", ";
        }
    }

    const selectedItem = this.dataItems.getItem(args.index);
    console.log("Item selecting: " + (selectedItem && selectedItem.name));
}

我希望访问列表视图索引

【问题讨论】:

    标签: angular nativescript


    【解决方案1】:

    可以链接列表视图

    <RadListView #myListView>
    

    然后在控制器中添加为

    @ViewChild('myListView', {static: false}) listViewComponent: RadListViewComponent;
    

    【讨论】:

    • 如果我使用此 listViewComponent.getSelectedItems() 不起作用,我想以 RadListView 访问列表视图,以便获取索引
    • listViewComponent.listView 应该给你RadListView。所以你可以打电话给listViewComponent.listView.getSelectedItems();
    • 很抱歉没有做清楚的描述。 this.listViewComponent 确实给出了 .getSelectedItem() 因为它声明为:RadListView 但是当我运行错误时显示 .getDSelectedItem 不是函数
    • @Manoj 感谢您指出 RadListView 是组件,所以我需要使用 .listView
    猜你喜欢
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2023-03-27
    • 2016-08-02
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 2017-02-14
    相关资源
    最近更新 更多