如何在钛中的特定索引处添加一行

How to add a row at a particular index in titanium

我有一个 table 钛金属,我添加了 3 行。在一种情况下,我从 table table.deleteRow(index) 中删除了第二行,经过一些过程后,我需要在该索引处添加一行。

谁能告诉我如何在特定索引处添加一行。

您可以使用

insertRowAfter : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TableView-method-insertRowAfter

insertRowBefore : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TableView-method-insertRowBefore 这样做

这是我试过的一个例子,输出在屏幕截图中可见。

Ti.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow();

var tableData = [ {title: 'Apples'}, {title: 'Bananas'}, {title: 'Carrots'}, {title: 'Potatoes'} ];

var table = Ti.UI.createTableView({
  data: tableData
});
win.add(table);
win.open();

table .insertRowAfter(3,{title: 'Inserted After'});
table .insertRowBefore(0,{title: 'Inserted Before'});