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

时间:2019-04-11 03:05:04

标签: nativescript

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

我试图理解这一点。但是解决方案是角度的,我无法在javascript中使用它。

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

Derived(int init) : Base(init) {

  a = process();
  b = process();
}

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

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

我只希望所选项目的背景发生变化。

1 个答案:

答案 0 :(得分:0)

我已经为您here更新了游乐场。 args.object给您列表视图本身。

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();
    },
相关问题