且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更改 ListView 中当前所选项目的背景颜色的问题 - Nativescript/Angular2

更新时间:2023-01-27 18:28:28

尝试

<ListView [items]="activeStockTakes" class="list-group">
    <ng-template let-activeStockTake="item" let-i="index">
        <StackLayout [class.highlight]="item.isSelected" (tap)="selectActiveStockTake(item, i)">
            <Label class="list-group-item" [text]="activeStockTake.UserCode + ' - ' + activeStockTake.Comment"></Label>
        </StackLayout>
    </ng-template>
</ListView>

然后:

selectActiveStockTake(item, i) {
  item.isSelected = !item.isSelected;
}

这是一个更干净的解决方案,应该可以完美运行.

This is a much cleaner solution and should work perfectly.