Angular2/Nativescript:如何突出显示ListView的选定项?

use*_*257 1 css nativescript angular2-nativescript

我已经阅读了Nativescript ListView文档并搜索了Google,无法找到任何方法来突出显示当前所选的Listview项目......这甚至可能吗?如果是这样我该怎么办呢?

我的代码:

<ListView [items]="activeStockTakes" class="list-group" (itemTap)="selectActiveStockTake($event)">
                    <template let-activeStockTake="item">
                        <StackLayout>
                            <Label class="list-group-item" [text]="activeStockTake.UserCode + ' - ' + activeStockTake.Comment"></Label>
                        </StackLayout>
                    </template>
                </ListView>
Run Code Online (Sandbox Code Playgroud)

Edd*_*gen 6

你当然可以!

在CSS中定义一个类"突出显示":

.highlight {
  background-color: #eee;
}
Run Code Online (Sandbox Code Playgroud)

然后根据视图中的条件分配它:

<StackLayout [class.highlight]="selectedItem && activeStockTake.UserCode === selectedItem.UserCode">
Run Code Online (Sandbox Code Playgroud)

selectedItem属性在组件中定义,并在列表中选择项目时进行分配/更新.