如何更改列表视图中所选项目的背景颜色

问题描述 投票:0回答:1

无法更改列表视图中所选项目的背景颜色。

我试图理解这一点。但解决方案是有角度的,我没有得到如何在JavaScript中使用它。

Issues changing the background colour of the currently selected item in a ListView - Nativescript/Angular2

onItemTap: function (args) {
      console.log('Item with index: ' + args.index + ' tapped');
      args.object.backgroundColor = "#3489db";
    },

在这里我可以改变完整列表视图的背景。

游乐场样本。 https://play.nativescript.org/?template=play-js&id=KZeq3j

我只想要选择的项目来改变它的背景。

nativescript
1个回答
0
投票

我为你更新了游乐场here。 args.object为您提供listview本身。

onItemTap: function (args) {
      for (var i = 0; i < this.countries.length; i++) {
        this.countries[i].bgColor = "#FFFFFF";
      }
      console.log(this.countries[args.index])
      this.countries[args.index].bgColor = "#3489db";
      args.object.refresh();
    },
© www.soinside.com 2019 - 2024. All rights reserved.