0

在后面的代码中以编程方式执行此操作(不绑定到 XML),一切正常,除了我的背景颜色在选择项目时不显示。没有错误,我的图像显示正常。我的代码有什么问题?(谢谢!)

我在跑步{N} CLI "tns-android":"version": "3.4.2", "nativescript-ui-listview": "3.5.1"

<GridLayout columns="auto, *">
    <StackLayout col="0" id="containers">
    </StackLayout>
    <StackLayout col="1" id="notes">
    </StackLayout>
</GridLayout>


function setContainers() {
    myCntnrPics.forEach(function (element) { // Need to it in ObservableArray
        pathToCntnrBitmapsArray.push(element);
    });

    let radListLeft = new listview.RadListView();
    // iOS NEEDS height set
    radListLeft.height = 2000;
    radListLeft.items = pathToCntnrBitmapsArray;
    let gridLayout = new listview.ListViewGridLayout();
    gridLayout.scrollDirection = "Vertical";
    radListLeft.selectionBehavior = "Press";
    radListLeft.itemSelected = "selected";
    radListLeft.on("itemSelected", function (ListViewEventData) {
        const item = pathToCntnrBitmapsArray.getItem(args.index);
        item.selected = true;
        console.log("itemSelected is true -----"); // This does not show up
    });
    radListLeft.on("itemTap", function (element){
        var selectedItemPath = pathToCntnrBitmapsArray.getItem(element.index).toString();
        console.log("on itemTap selectedItemPath: " + selectedItemPath); // shows correctly
    });
    if (application.android) {
        // Android needs H & W
        radListLeft.itemTemplate = "<StackLayout backgroundColor='{{ selected ? 'red' : 'white'}}'><Image src='{{ $value }}' height='123' width='123' loadMode='async' class='items'/></StackLayout>";
    } else if (application.ios) {
        radListLeft.itemTemplate = "<StackLayout backgroundColor='{{ selected ? 'red' : 'white'}}'><Image src='{{ $value }}' class='items'/></StackLayout>";
        gridLayout.itemHeight = 123;
        gridLayout.itemWidth = 123;
    }
    gridLayout.spanCount = 1;
    radListLeft.listViewLayout = gridLayout;
    let myContainers = page.getViewById("containers");
    myContainers.removeChildren();
    myContainers.addChild(radListLeft);
}
4

0 回答 0