我正在制作一个包含每行文本字段的tableview,但我遇到的问题是我不知道如何访问它们的值。
这是我的代码:
function TextFieldValueWindow(title, value1,value2) {
var self = Ti.UI.createWindow({
backgroundImage:'/images/backgrounds/BG_table_view.jpg',
fullscreen :false,
navBarHidden:true
});
var my_navbar = Ti.UI.createLabel({
height:'25dp',
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:'14dp'},
backgroundColor:'#2451A1',
width:'100%',
color:'#fff',
textAlign:Ti.UI.TEXT_ALIGNMENT_CENTER,
text:title,
top:0
});
var data = [];
var xhr = Ti.Network.createHTTPClient();
xhr.timeout = 1000000;
xhr.open("GET","http://xxxx.com/xxx?m="+value1+"");
xhr.onload = function() {
try {
var students = JSON.parse(this.responseText);
for (var c=0;c<students.length;c++){
var id = students[c].id;
var name = students[c].name;
var lastName = students[c].lastName;
var row = Ti.UI.createTableViewRow({height:'280dp',height:'30dp',RowStudentID:id,backgroundColor: 'transparent'});
var name_label = Ti.UI.createLabel({
text:name,
left:'10dp',
width:'120dp',
top:'5dp',
bottom:'2dp',
height:'18dp',
textAlign:'left',
color:'white',
font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
});
var lastname_label = Ti.UI.createLabel({
text:lastName,
left:'10dp',
width:'120dp',
top:'25dp',
bottom:'2dp',
height:'18dp',
textAlign:'left',
color:'white',
font:{fontFamily:'Trebuchet MS',fontSize:14,fontWeight:'bold'}
});
var textfieldinput = Titanium.UI.createTextField({
width:'50dp',
right:'5dp',
top:'10dp',
height:'40dp',
value:'',
keyboardType:Ti.UI.KEYBOARD_NUMBER_PAD,
//borderStyle:Titanium.UI.INPUT_BORDERSTYLE_NONE
});
row.add(lastname_label);
row.add(name_label);
row.add(textfieldinput);
row.className = 'item'+c;
data[c] = row;
}
var tableview = Titanium.UI.createTableView({
data:data,
top:'25dp',
height:'370dp',
backgroundColor: 'transparent',
minRowHeight:'50dp'
});
self.add(my_navbar);
self.add(tableview);
}catch(E){
alert(E);
}
var notasBtn = Titanium.UI.createButton({
title:'btn',
width:'140dp',
height:'40dp',
borderRadius:'2dp',
bottom:'10dp',
verticalAlign:'center',
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:'14dp'}
});
self.add(notasBtn);
notasBtn.addEventListener('click', function(e){
var dataNotas=[];
var _rowData = tableview.data[0].rows;
for ( var x in _rowData) {
Ti.API.info(??);
}
});
};
self.addEventListener('open', function() {
xhr.send();
});
return self;
};
module.exports = TextFieldValueWindow;
我还没有看到一个关于如何获取TextField值(textfieldinput.value)的好例子,因此无法继续移动:(
希望你能帮助我们。
发现它!
“_ rowData [x] .children [2] .value”获取行内文本字段内的值。 x是行的索引,2是子视图,它是TableViewRow中的第三个对象
答案 0 :(得分:0)
您还可以将子标签设置为行的属性。
var row = Ti.UI.createTableViewRow({...});
row.name = Ti.UI.createLabel({...});
row.lastName = Ti.UI.createLabel({...});
row.textField = Ti.UI.createTextField({...});
row.add(row.name);
row.add(row.lastName);
row.add(row.textField);
然后您可以将它们作为行属性访问:
notasBtn.addEventListener('click', function(e){
var dataNotas=[];
var _rowData = tableview.data[0].rows;
for ( var x in _rowData) {
Ti.API.info(_rowdata.textField.value);
}
});