Reputation: 5
How do I add an event listener so that a table is updated when the window/tab is in focus? My Current code works for webViews but I am unsure as how to apply it to tableViews. win.addEventListener('focus',function(e){webview.reload();});
Upvotes: 0
Views: 1645
Reputation: 1610
Yes, You can perform in your current Code.
win.addEventListener('focus', function(e){
tableView.setData(newData); // this is always add update Array
});
for example
var win = Ti.UI.createWindow();
var data = [
{title:"Row 1"},
{title:"Row 2"},
{title:"Row 3"}
];
var tableView = Ti.UI.createTableView({
data: data
});
win.add(tableView);
win.open();
Try again this
var win = Ti.UI.createWindow();
var data = [
{title:"Row 1"},
{title:"Row 2"},
{title:"Row 3"}
];
var tableView = Ti.UI.createTableView({
data: data
});
data = [
{title:"Row 1"},
{title:"Row 2"},
{title:"Row 3"},
{title:"Row 4"},
{title:"Row 5"},
];
win.addEventListener('focus',function(){
tableView.setData(data);
});
win.add(tableView);
win.open();
Upvotes: 0
Reputation: 76
Say you have your table, defined as:
var tableData = [{title: 'Elephants'}, {title: 'Donkeys'}, {title: 'Falcons'}]
var tableView = Ti.UI.createTableView({
data: tableData
})
win.add(tableView)
And an array called newData
that has the new information you want to place in the table. Have you tried doing the following?
win.addEventListener('focus', function(e){
tableView.data = newData
})
Let me know if you need more information or if this doesn't fit your needs.
Upvotes: 0
Reputation: 33345
create a method that reloads the data for the table and call table.setData(_tableData)
Upvotes: 3