Reviewing the following XML:
<ListView items="{{ lists }}" itemTap="itemTapped">
<ListView.itemTemplate>
<StackLayout class="list-group-item" orientation="horizontal">
<Label text="{{ name }}" class="item-name" horizontalAlignment="center" />
</StackLayout>
</ListView.itemTemplate>
</ListView>
In the itemTapped
function, the goal is to modify the StackLayout container's background color.
exports.itemTapped = function (args) {
console.log(args.object.backgroundColor)
args.object.backgroundColor = 'red'
console.log(args.object.backgroundColor)
}
Upon clicking a list item in the app, the console logs reveal:
CONSOLE LOG file:///app/pick/pick-page.js:111:14: undefined
CONSOLE LOG file:///app/pick/pick-page.js:113:14: #FF0000
CONSOLE LOG file:///app/pick/pick-page.js:111:14: undefined
CONSOLE LOG file:///app/pick/pick-page.js:113:14: #FF0000
An attempt was made using
args.object.className = 'selected-item'
to set the CSS property background-color: red;
, but it did not yield the desired result.
What is the best approach for dynamically changing the color or providing visual feedback that a ListView item has been tapped?