Titanium 更新项目上列表视图内的文本单击appcelerator
钛加速计 无法在单击下面的按钮时更新listview代码中的文本:Titanium 更新项目上列表视图内的文本单击appcelerator,titanium,titanium-mobile,titanium-android,Titanium,Titanium Mobile,Titanium Android,钛加速计 无法在单击下面的按钮时更新listview代码中的文本: { type : 'Ti.UI.View', bindId : 'vwqtySelection', properties : { top : '30dp', height : '50dp', //backgroundColor: 'red',
{
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 : '+',
}
}]
}
>项目点击选择按钮上更新文本的位置点击
要更新按钮单击时的文本,即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') {
}
}};
在下面出错
消息:未捕获类型错误:无法读取未定义的属性“properties”这是如何在
列表视图中编辑UI元素的示例。
每个列表项
都包含一个标签
,该标签包含一个数字和一个加号标签,当您单击加号标签时,它应该增加该列表项中的数字
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>
希望这有帮助,如果您需要任何修改,请告诉我。我不理解您的代码,您如何使用列表视图,以及上面的代码到底做了什么?无论如何,要更新列表项中的字段,最简单的方法是获取该项,编辑它,然后在列表视图中更新它,只需解释一下您的代码,我将提供帮助,我将添加一个合金示例,说明如何在列表视图中编辑标签。
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 });
}