【发布时间】: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