我需要将listview中点击的项目的URL,标题和日期从DashboardController传递到VideoPlayerController。我将传递给VideoPlayerController的网址应该使视频自动播放。我该怎么办?
这是DashboardController.js的代码
var args = $.args;
var sections = [];
//JSON to populate the listview
var videoInfo = [{
pic : "/Images/playButton.png",
info : "This in the the title for the first video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}, {
pic : "/Images/playButton.png",
info : "This in the the title for the second video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}, {
pic : "/Images/playButton.png",
info : "This in the the title for the third video.",
date : "03/07/2017",
url : "https://youtu.be/zkOSR0ZRb9khttps://youtu.be/zkOSR0ZRb9k"
}];
function populateListView() {
Ti.API.trace("[DashboardController.js >> populateListView() >>]");
if (!_.isEmpty(videoInfo)) {
for (var i = 0; i < videoInfo.length; i++) {
var item = {
template : "videoTemplate",
iconId : {
image : videoInfo[i].pic
},
titleId : {
text : videoInfo[i].info
},
dateId : {
text : videoInfo[i].date
},
urlId : {
text : videoInfo[i].url
},
properties : {
backgroundColor : "transparent"
}
};
sections.push(item);
}
$.listSection.setItems(sections);
}
}
populateListView();
$.lView.addEventListener('click',function(e){
var dataItem = $.listSection.get(e.itemIndex) ;
var videoController = Alloy.createController('VideoPlayerController',{
"url":$.url,
"title":$.info,
"date":$.date
}).getView();
});
这是Dashboard Controller.xml的代码
<Alloy>
<View id="win2" class="container">
<View id = "v1" class ="view1" layout ="horizontal" >
<Button class="btnBack" ></Button>
<Label class = "label1">LIST VIEW EXAMPLE</Label>
</View>
<View class="view2">
<TextField id = "txtSearch"></TextField>
</View>
<ListView id = "lView" class = "list1" >
<Templates>
<ItemTemplate name="videoTemplate">
<View class = "viewTemplate" layout = "horizontal" >
<ImageView bindId="iconId" id="pic" />
<View class = "viewTitle" layout = "vertical" >
<Label bindId="titleId" id="info" />
<View class="viewDtUrl" layout="horizontal" >
<Label bindId="dateId" id="date" />
<Label bindId="urlId" id ="url" />
</View>
</View>
</View>
</ItemTemplate>
</Templates>
<ListSection id = "listSection">
</ListSection>
</ListView>
</View>
</Alloy>
And this is the code for VideoPlayerController.xml
<Alloy>
<View class="container">
<VideoPlayer class = "video"></VideoPlayer>
<View class="videoInfoView" layout="vetical" backgroundColor="blue">
<Label class="titleInfo"></Label>
<View class = "infoLabel" layout="horizontal" backgroundColor="yellow">
<Label class="dateInfo"></Label>
<Label class="urlInfo"></Label>
</View>>
</View>
</View>
</Alloy>