我正在使用钛来开发 Android 应用程序。我正在使用以下代码来显示数据并使用 TableView 。当我单击 comment_btn 时, TableView 中会附加一个新行。它工作正常。但是当我单击后退按钮或转到另一个窗口并再次返回到同一个窗口时,我添加了新行,新添加的行不保留。我也尝试过 insertRowAfter 但它给了我相同的结果。我使用了以下代码:
for (var i=0;i<5;i++)
{
var row = Ti.UI.createTableViewRow({height:'auto',className:"row"});
var comments = Ti.UI.createLabel(
{
text:'new comment',
height:'auto',
font:{fontSize:12, fontFamily:'Helvetica Neue'},
color:'#000',
width:'auto',
textAlign:'left',
top:10,
left:40,
});row.add(comments);
}
comment_table.setData(data);
commnet.add(comment_table);
var comment_btn = Titanium.UI.createButton(
{
title:'comment',
height:60,
width:60,
bottom:-5,
left:-2,
});
comment.add(comment_btn);
var comment_box = Titanium.UI.createTextArea({
borderRadius:5,
backgroundColor:'#EEE',
editable: true,
height:30,
width:200,
top:10,
font:{fontSize:15,fontFamily:'Marker Felt'},
color:'#000',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderRadius:5,
});
comment.add(comment_box);
comment_btn.addEventListener('click', function()
{
comment_table.appendRow({title:comment_box.value});
//comment_table.insertRowAfter(3,{'title':comment_box.value});
}
最佳答案
- 该对象必须属于 Row 类型:
comment_table.appendRow(ROW_TYPE_OBJECT)
。 - 如果您要返回(假设按后退按钮),则当前窗口将关闭 该窗口的所有子窗口都表示 View 、按钮、表格将被删除。
- 假设当前Tableview的窗口为widnow1,现在你打开window2,如果你是 从 window2 转换到 window1 然后您可以看到带有新附加行的表 窗口1。
解决方案:
- 创建一个全局数组(
data[]
),其中包含您要访问的行和行 追加。 - 加载当前window1时,检查data是否为null。
- 如果数据不为空,则从全局数组数据加载 TableView
tableview.setData(data)
,否则加载新行。
关于javascript - 移动应用程序的 TableView 中的附加行必须永久保留(钛),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7631325/