开发者

i want to get selected row value from tableview and copy into textfiled for appcelerator

hi all i want to get selected row value into textfield so how can i copy the value into the textfiled. so how can i do this...my_combo is textfiled Code -:

var Tab_data = [

     { title:'Row 1', hasChild:true },
     { title:'Row 2', hasChild:true },
     { title:'Row 3', hasChild:true },
     { title:'Row 4', hasChild:true }
];


var tab = Titanium.UI.createTableView({
    top:43,
    data:开发者_开发问答Tab_data
});

tab.selectionIndicator=true;

tab.addEventListener('click',function(e) {

    var ind = e.index;

    if(e.selectRow)
    {
        Titanium.API.inof(' Selected clicked');
        my_combo.value = e.selectRow.title;
    } 

});


1) Create the row and attach the rowid to it, or whatever other data you want to associate to a row.

var row = Ti.UI.createTableViewRow();
row.rowId = 1;
row.myText = "hello world";

2) Add click event listener to the table:

tableView.addEventListener('click', selectRow);

3) In selectRow function, get the data.

function selectRow(e) {
 var rowId = e.rowData.rowId;
 var myText = e.rowData.myText;
 myTextField.value = myText;
}


You can just simply add 'rowid' to each row. And make an eventListener on your table like you did and retrieve the value with 'e.row.rowid'.


you should put in constructor like this

var row = Titanium.UI.createTableViewRow({
    hasChild:true,
    title:rows.fieldByName('title'),
    rowId:rows.fieldByName('id'),
    path:'nextView.js'

    }); 


tab.addEventListener('click',function(e) {

    var ind = e.index;

    if(e.selectRow)
    {
        Titanium.API.inof(' Selected clicked');
        my_combo.value = e.rowData.title;
    } 
});


Just replace e.selectRow with e.row in your code.

tab.addEventListener('click',function(e) {

    var ind = e.index;

    if(e.row)
    {
        Titanium.API.inof(' Selected clicked');
        my_combo.value = e.row.title;
    } 

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜