我有一个数据表,在 eventlistener 单击时,该行将成为一个详细窗口,其中包含所选行的数据。我将数据作为标签,但我想将一些数据显示为带有行标题的表格(特别是我的 vars、mon、tues、weds、thurs、fri、sat、sund)。我试图在事件监听器中创建一个表,但它没有出现。我将如何处理这个?下面是我的代码:
var win = Titanium.UI.currentWindow;
var data = [];
var barList = Titanium.UI.createTableView({
height: 366,
width: 320,
top: 0,
left: 0
});
win.add(barList);
barList.addEventListener('click', function (e) {
Ti.API.info('data: ' + JSON.stringify(e.rowData.data));
var detail = Ti.UI.createWindow({
backgroundColor: '#fff',
data: e.rowData.data, // use rowData
title: e.rowData.data.name, // now you can access name as well as address
});
var lbl = Ti.UI.createLabel({
text: JSON.stringify(e.rowData.data.address),
top: 10
});
detail.add(lbl); // just so you can see it here as well
var mon = Ti.UI.createLabel({
text: e.rowData.data.mon_special,
top: 30
});
detail.add(mon);
var tues = Ti.UI.createLabel({
text: e.rowData.data.tues_special,
top: 50
});
detail.add(tues);
var weds = Ti.UI.createLabel({
text: e.rowData.data.weds_special,
top: 50
});
detail.add(weds);
var thurs = Ti.UI.createLabel({
text: e.rowData.data.thurs_special,
top: 50
});
detail.add(thurs);
var fri = Ti.UI.createLabel({
text: e.rowData.data.fri_special,
top: 50
});
detail.add(fri);
var sat = Ti.UI.createLabel({
text: e.rowData.data.sat_special,
top: 50
});
detail.add(sat);
var sund = Ti.UI.createLabel({
text: e.rowData.data.sun_special,
top: 50
});
detail.add(sund);
detail.open({
modal: true
});
});
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function () {
var json = JSON.parse(this.responseText);
Ti.API.info(json.length);
for (var i = 0; i < json.length; i++) {
var row = Titanium.UI.createTableViewRow({
className: 'bar-row',
data: json[i].bar, // pass everything because you also use name later on
hasChild: true,
filter: json[i].bar.name
});
var titleLabel = Titanium.UI.createLabel({
text: json[i].bar.name,
font: {
fontSize: 14,
fontWeight: 'bold'
},
left: 70,
top: 5,
height: 20,
width: 210
});
row.add(titleLabel);
var addressLabel = Titanium.UI.createLabel({
text: json[i].bar.address,
font: {
fontSize: 10,
fontWeight: 'normal'
},
left: 70,
top: 25,
height: 40,
width: 200
});
row.add(addressLabel);
var iconImage = Titanium.UI.createImageView({
text: json[i].bar.logo_file_name,
width: 50,
height: 50,
left: 10,
top: 10
});
row.add(iconImage);
data.push(row);
}
barList.setData(data);
};
xhr.open('GET', 'http://example.com/bars.json');
xhr.send();