我从 ArrowDB 查询并获得了事件列表,现在我想要单击特定视图时的每个事件详细信息。我的代码如下所示,除了它将所有查询事件的详细信息放在打开的窗口上,并在顶部显示最后一个查询事件。
请问我该怎么做?我的大脑无法解决这个问题。
Cloud.Events.query(function (e) {
if (e.success) {
alert('Success:\n' + 'Count: ' + e.events.length);
for (var i = 0; i < e.events.length; i++) {
var event = e.events[i];
alert('id: ' + event.id + '\n' +
'name: ' + event.name + '\n' +
'start time: ' + event.start_time);
var holdview = Ti.UI.createView({
backgroundColor: '#d3d3d3',
backgroundImage: 'testview.png',
width: '85%',
height: '85%',
top: '5%'
});
//adding holdview to a scrollable view
xperiencesscrollableview.addView(holdview);
var testlabeltitle = Ti.UI.createLabel({
top: '5%',
width: '65%',
height: '10%',
left: '20%',
text: event.name
});
//it works well to this point and shows each event separately on views
holdview.add(testlabeltitle);
//adding forEach as suggested as an answer
e.events.forEach(function(event) {
holdview.addEventListener('click',function(e){
var detailstestname = Ti.UI.createLabel({
top: '5%',
width: '65%',
height: '10%',
left: '20%',
text: event.name,
color: 'black',
backgroundColor: 'white'
});
//Page for event details
eventdetailspage.open();
eventdetailspage.add(detailstestname);
});
});
//at this point it messes up
}
}
});