【问题标题】:how to change background color of selected item in listview如何更改列表视图中所选项目的背景颜色
【发布时间】:2019-04-11 03:05:04
【问题描述】:

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

我试图理解这一点。但解决方案是有角度的,我不知道如何在 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】:

    我已经为你更新了游乐场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();
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多