Nativescript: Listview items are reusing when scrolling

前端 未结 2 1621
梦谈多话
梦谈多话 2021-01-26 06:21

I am trying to add products to Cart by clicking STORE []. Then, I am changing label\'s color for that added list.

After that,

2条回答
  •  无人共我
    2021-01-26 06:45

    you are directly changing color of the rendered object because of which when object is recycled it persist that color.

    you can achieve same effect by changing object property when clicked. and based on that property applying styles. like className="{{isClicked?'clickedCart':'notClickedCart'}}" or stle.color="{{isClicked?'red':'blue'}}"

    here is updated playground demo:https://play.nativescript.org/?template=play-js&id=T6sna8&v=8

    Coding

    .js

    exports.cartColorChange = function(args) {
        var lbl = args.object;
        var item=lbl.bindingContext;
        var index = secondArray.indexOf(item)
        console.log("Clicked item with index " + index);
        item.isClicked = !item.isClicked;
        secondArray.setItem(index,item);
        // lbl.color = "rgb(171, 0, 230)";
    };
    

    .xml

    
    
    
    
      
    
    
    

    .css

    Label.clickedCart{
        color:rgb(171, 0, 230);
    }
    
    Label.notClickedCart{
        color:gray;
    }
    

提交回复
热议问题