2013-06-28 40 views
0

我有一个两个选项卡布局。点击第一个选项卡按钮时,将使用远程检索的数据填充行。这与第二个选项卡相同,但数据的布局不同。钛:自动选择动态创建的行的第一行

我的问题是,当您切换标签之间我需要触发每个选项卡的第一行上的单击事件。

我正在构建这个应用程序仅适用于android。

任何帮助是极大的赞赏...

编辑:这是头顶哑代码,希望让更多的意义。

leftTableView = Ti.UI.createTableView({ 
    data: populateTableView(0), 
    allowsSelection:true 
}); 

function populateTableView(byType) 
{ 
for(length of array loop){ 
    var tableViewRow=Ti.UI.createTableViewRow({ 
     my_obj:myObj[i] 
    }); 

    tabledata=[] 

    tableViewRow.addEventListener('click',function(e){ 
     e.row.setBackgroundImage('/images/selected-row-background.png'); 
    } 

    if byType 0 

     loop array display row for each object element 
     tableData.push(tableViewRow); 
     return tabledata 


    if byType 1 

     loop array display row for each object element, display differently 
     tableData.push(tableViewRow); 
     return tabledata 
} 
} 

tab 1 click event listener 

populateTableView(0); 
leftTableView.data[0].rows[0].fireEvent('click');//this fires but says e.row.setBackgroundImage is undefined 

tab 2 click event listener 

populateTableView(1) 
leftTableView.data[0].rows[0].fireEvent('click');//this fires but says e.row.setBackgroundImage is undefined 

回答

1

监听在tabGroup模糊事件并采取行动作为突出部中的每一个成为活动选项卡

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.TabGroup-event-blur

tabGroup.addEventListener('blur', function(_event) { 
    var activeTab = _event.tab; 

    // now that you have the activeTab, get the window, then the 
    // table and call a method to simulate a click on the first 
    // row 
}); 

传递数据点火事件

var row = leftTableView.data[0].rows[0]; 
row.fireEvent('click', { row : row }) 
+0

Hey Aaron, I s应该提到这一点,我的标签不打开/关闭窗口,他们改变标签下面的行。根据点击哪个标签,数据显示的方式不同。我在每个选项卡上都有一个“点击”侦听器,当它们被选中时,表格视图被填充,例如leftTableView.setData(function1)和leftTableView.setData(function2)。一旦这个动作完成,我需要从动态添加的行中选择第一行。在我添加的选项卡单击事件侦听器上的setData调用之后。 leftTableView.selectRow(0),这不会导致任何错误,但不会选择行。 – Random

+0

根本不关注你......也许有些代码? –

+0

我已经提供了一些虚拟代码,我的头顶 – Random