Angular 如何从nativescript中的ListView点击事件获取特定列表项
我正在尝试使用angular2+typescript从tap事件获取数据: 这是HTML组件:Angular 如何从nativescript中的ListView点击事件获取特定列表项,angular,typescript,nativescript,Angular,Typescript,Nativescript,我正在尝试使用angular2+typescript从tap事件获取数据: 这是HTML组件: <RadListView row="1" [items]="groceryList" [class.visible]="listLoaded" (tap)="seeItem($event)" swipeActions="true" (itemSwipeProgressStarted)="onSwipeCellStarted($event)"> <ng-templat
<RadListView row="1" [items]="groceryList" [class.visible]="listLoaded" (tap)="seeItem($event)"
swipeActions="true" (itemSwipeProgressStarted)="onSwipeCellStarted($event)">
<ng-template let-item="item">
<Label [text]="item.name" class="p-15 list-item"></Label>
</ng-template>
<GridLayout *tkListItemSwipeTemplate columns="*, auto">
<StackLayout id="delete-view" col="1" (tap)="delete($event)" class="delete-view">
<Image src="~/images/delete.png"></Image>
</StackLayout>
</GridLayout>
</RadListView>
点击以下按钮时,“删除”事件(在此组件中)使用相同的逻辑工作:
delete(args: ListViewEventData) {
let grocery = <Grocery>args.object.bindingContext;
this.groceryService.delete(grocery.id)
.subscribe(() => {
let index = this.groceryList.indexOf(grocery);
this.groceryList.splice(index, 1);
});
}
delete(args:ListViewEventData){
设=args.object.bindingContext;
this.groceryService.delete(screery.id)
.订阅(()=>{
设index=this.groceryList.indexOf(杂货店);
这个.groceryList.splice(索引1);
});
}
我是NativeScript的初学者,非常感谢您的帮助,如果您希望打开该项目,以下是您需要进行的更改 替换
<ng-template let-item="item">
<Label [text]="item.name" class="p-15 list-item"></Label>
</ng-template>
试试这个,它应该会起作用。如果您使用的是RadListview,而在杂货店的示例中则是ListView,那么这将不起作用。因此,获取索引
var index=args.itemIndex编码>然后按该索引过滤数组,即this.groceryList[index]代码>非常感谢,它起作用了。这不起作用,因为他想在执行刷卡操作时获得物品。
delete(args: ListViewEventData) {
let grocery = <Grocery>args.object.bindingContext;
this.groceryService.delete(grocery.id)
.subscribe(() => {
let index = this.groceryList.indexOf(grocery);
this.groceryList.splice(index, 1);
});
}
<ng-template let-item="item">
<Label [text]="item.name" class="p-15 list-item"></Label>
</ng-template>
<ng-template let-item="item">
<Label [text]="item.name" (tap)="seeItem(item)" class="p-15 list-item"></Label>
</ng-template>
seeItem(item: Grocery) {
console.log('item ', item);
console.log('in case');
}