1

Titanium Appcelerator 无法在单击下面的按钮时更新列表视图代码中的文本:

{
            type : 'Ti.UI.View',
            bindId : 'vwqtySelection',
            properties : {
                top : '30dp',
                height : '50dp',
                //backgroundColor: 'red',
                width : require('main').XhdpiSupport(150),
                right : '90dp',
                zIndex : 10

            },
            childTemplates : [{
                type : 'Ti.UI.Button',
                bindId : 'btnMinus',
                properties : {
                    left : '15dp',
                    color : '#676972',
                    title : '-',
                    width : require('main').XhdpiSupport(30),
                    height : require('main').XhdpiSupport(22),
                }

            }, {
                type : 'Ti.UI.Label',
                bindId : 'qtyValue',
                properties : {
                    //touchenabled : false,
                    left : '50dp',
                    color : '#676972',
                    text : '4',
                    textAlign : 'center',
                }

            }, {
                type : 'Ti.UI.Button',
                bindId : 'btnPlus',
                properties : {
                    left : '79dp',
                    color : '#676972',
                    title : '+',
                }
            }]  
        }

> Itemclick 选择在哪里更新按钮点击 文本想要更新按钮点击文本,即 4 到 2

下面的代码我试过

    scrlView.addEventListener('itemclick', function(e) {

         if (e.bindId === 'btnMinus') {
             item = section.getItemAt(e.itemIndex);
                e.section.qtyValue.properties.text = "2";
                e.section.updateItemAt(e.itemIndex, item); 
               //here not able to  update text 4 to 2 
        } else if (e.bindId === 'btnPlus') {

        }
}};

出现错误消息:未捕获的类型错误:无法读取未定义的属性“属性”

4

1 回答 1

1

这是一个如何在listView. 每个都ListItem包含Label一个数字和一个加号标签,当您单击加号标签时,它应该增加该 listItem 中的数字。

index.xml 文件:

<ListView id="listView" class="listView" defaultItemTemplate="template">
    <Templates>
        <ItemTemplate name="template" layout='horizontal'>
            <Label bindId="number" id="number" left=20>0</Label>
            <Label bindId="add" id="add" right=20 onClick="addOneToCurrentNumber">+</Label>
        </ItemTemplate>
    </Templates>

    <ListSection>
        <ListItem number:text='0' />
        <ListItem number:text='-50' />
        <ListItem number:text='100' />
        <ListItem number:text='1024' />
    </ListSection>
</ListView>

index.js 文件:

function addOneToCurrentNumber(e) {
    var row = $.listView.sections[0].getItemAt(e.itemIndex);
    var number = parseInt(row.number.text);
    number++;
    row.number.text = number;
    $.listView.sections[0].updateItemAt(e.itemIndex, row, { animated:true });
}

希望这会有所帮助,如果您需要任何修改,请告诉我。

于 2015-04-14T18:12:32.577 回答