Arrays Appcelerator钛:使用eventListener&;视图上数据库阵列上的fireEvent
我刚接触钛。我在这方面有一些问题已经有一段时间了。非常感谢您的帮助 我有一个数组循环,通过数据库检索图像和标签。这些都存储在一个视图中。我将向视图中添加事件侦听器,然后向侦听器中添加fire事件,以在新窗口中打开选定的图像,并将该视频的id用作参考点,以便在新窗口中播放选定的视频。希望我的代码更有意义 问题是,偶数侦听器只返回数据库中最后一行的值,而不是用户单击的视频图像的信息Arrays Appcelerator钛:使用eventListener&;视图上数据库阵列上的fireEvent,arrays,events,for-loop,onclicklistener,appcelerator,Arrays,Events,For Loop,Onclicklistener,Appcelerator,我刚接触钛。我在这方面有一些问题已经有一段时间了。非常感谢您的帮助 我有一个数组循环,通过数据库检索图像和标签。这些都存储在一个视图中。我将向视图中添加事件侦听器,然后向侦听器中添加fire事件,以在新窗口中打开选定的图像,并将该视频的id用作参考点,以便在新窗口中播放选定的视频。希望我的代码更有意义 问题是,偶数侦听器只返回数据库中最后一行的值,而不是用户单击的视频图像的信息 function getChannelVideos(){ // create an empty data ar
function getChannelVideos(){
// create an empty data array
var video = [];
// create the httpRequest
var xhr = Titanium.Network.createHTTPClient();
xhr.open('GET','getVideoFeed.php?chid='+channelView.channelId);
// this method will be called when the request is complete
xhr.onload = function()
{
// parse json coming from the server
var json = JSON.parse(this.responseText);
// if Channel Videos are returned
if(json.channelVideos)
{
for (var i = 0; i < json.channelVideos.length; i++){
var video = Ti.UI.createView({ // creates video view
width:'60%', // sets height
backgroundColor: 'transparent',
});
var videoThumb = Ti.UI.createImageView({ // creates thumb
image:json.channelVideos[i].vThumb,
width:'100%', // sets height
top:150 + i*200, // positions from top
backgroundColor: '#000'
});
video.add(videoThumb); // adds thumb to video view
var videoTitle = Ti.UI.createLabel({ // creates label
text:json.channelVideos[i].vTitle,
font:{
fontSize:12
},
color:'#fff',
backgroundColor:'#000',
textAlign:'center',
width:'100%',
height:20,
top:140 + i*200, // positions from top
});
video.add(videoTitle); // adds video title to video view
var videoSpeaker = Ti.UI.createLabel({ // creates Label
text:json.channelVideos[i].vSpeaker,
font:{
fontSize:12
},
color:'#fff',
backgroundColor:'#000',
textAlign:'center',
width:'100%',
height:20,
top:295 + i*200, // positions from top
});
video.add(videoSpeaker); // adds speaker name to video view
var videoPlay = Ti.UI.createImageView({
image:'/images/light_play.png',
top:215 + i*200, // positions from top
});
video.add(videoPlay); // adds playbutton to videoview
chContentAreaView.add(video); // adds video view to scrollview
var vId=json.channelVideos[i].vId;
video.vId = vId; // Here vId is custom property of video
video.addEventListener('click', function(e){
alert(e.source.vId);
Ti.App.fireEvent('videoPlay',{
videoId:e.source.vId
});
});
}
}
};
// this method will be called if there is an error
xhr.onerror = function(){
alert(this.error + ': ' + this.statusText);
return false;
};
// open the httpRequest
xhr.setRequestHeader("contentType","application/json; charset=utf-8");
xhr.send();
}
函数getChannelVideos(){
//创建一个空数据数组
var-video=[];
//创建httpRequest
var xhr=Titanium.Network.createHTTPClient();
open('GET','getVideoFeed.php?chid='+channelView.channelId);
//请求完成时将调用此方法
xhr.onload=函数()
{
//解析来自服务器的json
var json=json.parse(this.responseText);
//如果频道视频被返回
if(json.channelVideos)
{
对于(var i=0;ivideo.vId=json.channelVideos[i].vId
,如:
var video=Ti.UI.createView({//创建视频视图
宽度:'60%,//设置高度
背景色:“透明”,
vId:json.channelVideos[i].vId
});videoThumb
、videoTitle
、videoSpeaker
、videoPlay
等使用属性touchEnabled:false
我认为通过这样做,所有的事情都会很好地工作。您正在使用哪个sdk?您好,Swand。我使用Tianium SDK 3.5.1 Athanks提供建议。尝试了它们,仍然不起作用:我当前的代码如下所示:video.addEventListener('click',function(e){alert(e.source.vId);Ti.App.firevent('videoPlay',{videoId:e.source.vId});});我的视图如下所示:var video=Ti.UI.createView({//创建视频视图宽度:'60%,//设置高度背景色:'transparent',vId:json.channelVideos[i].vId});所有其他图像、标签等都已启用touchEnabled:false,如您所建议的