我正在制作每行中包含一些文本字段的表格视图,但我遇到的问题是我不知道如何访问它们的值。
这是我的代码:
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 中的第三个对象