Je fais une application simple sur le titane en utilisant la vue de table. J'ai une ligne personnalisée avec une case à cocher sur le côté gauche. Voici mon code:Comment supprimer une ligne sélectionnée dans titanium tableview?
var pickingData = [];
for (var i = 0; i<25; i++){
var row = Ti.UI.createTableViewRow({
className:'forumEvent', // used to improve table performance
backgroundSelectedColor:'cyan',
layout:'vertical'
});
if (Titanium.Platform.osname === 'android'){
var checkbox = Ti.UI.createSwitch({
style:Ti.UI.Android.SWITCH_STYLE_CHECKBOX,
value:false,
left:10
});
row.add(checkbox);
}
var rndMatNo = (randomInt(50000)+10000) //randomInt is my random number function
var lblMatNo = Ti.UI.createLabel({
realValue:rndMatNo,
text:'Mat No : ' + rndMatNo,
font:{fontFamily:'Arial', fontSize:DefaultFontSize, fontWeight:'bold'},
left:10,
color:'#222'
});
row.add(lblMatNo);
pickingData.push(row);
}
var tempPickingTable = Titanium.UI.createTableView({
data:pickingData,
editable: Titanium.Platform.osname === 'iphone' ? true : false,
name:'Picking table'
});
tempPickingTable.addEventListener('longclick',function(e){
for (var i=0, length=tempPickingTable.data[0].rows.length;i<length;i++){
if (tempPickingTable.data[0].rows[i].children[0].value === true){
tempPickingTable.deleteRow(i); //Still error when i'm using delete row because index out of bound
}
}
});
Tout ce que je veux, c'est de supprimer la ligne en fonction de la case cochée. J'ai essayé de faire une boucle pour chaque ligne et cochez la case, puis supprimez la ligne, mais elle me donne toujours l'index d'erreur hors limite.
Est-ce que quelqu'un sait comment faire cela? merci à l'avance ..
Salut Dawson .. Merci pour votre réponse .. cela fonctionne parfaitement pour moi .. :) –