【发布时间】:2017-07-05 17:14:38
【问题描述】:
我在代码中定义了一个 JSON,其中包含图像、标题、日期和 URL。这将用于填充列表视图。在任何列表项的单击事件中,我需要导航到不同的控制器并在其中呈现视图,其中包含根据单击的列表项的 url 播放视频的视频播放器,并且我也想显示日期和标题。 我不明白如何在 itemClick 事件中对此进行编码。请帮忙!
这是我的 DashboardController .js 文件。
Alloy.createController('VideoPlayerController',videoInfo[i]).getView();
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.getItemAt(e.itemIndex);
});
DashboardController 的 .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>
这是将渲染视频播放器 (VideoPlayerController) 的控制器的 .xml 文件是这样的:
<Alloy>
<View class="container">
<VideoPlayer class = "video"></VideoPlayer>
<View class="videoView">
<Label class="titleInfo"></Label>
<View class = "infoLabel">
<Label class="dateInfo"></Label>
<Label class="urlInfo"></Label>
</View>>
</View>
</View>
</Alloy>
【问题讨论】:
标签: listview appcelerator