浏览appcelerator中的不同控制器

时间:2017-07-06 12:29:59

标签: controller views appcelerator navigationbar

我想在appcelerator中列表项的itemclick事件中从DashboardController导航到VideoPlayerController。 但它给我一个错误,说无法找到$ .win2(这也是DashboardController中使用的视图)。

这是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('itemclick',function(e){
    Ti.API.trace("[DashboardController.js  >>  Function to open VideoPlayerController >>]");
    var dataItem = videoInfo[e.itemIndex];//$.listSection.getItemAt(e.itemIndex) ;
    Ti.API.trace("Data Item is : ",dataItem);
    var videoController = Alloy.createController('VideoPlayerController',{
    "url":dataItem.url,
    "title":dataItem.info,
    "date":dataItem.date
    }).getView();
    $win2.add(videoController);
    //videoController.open();
});

这是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">
            <SearchBar class="searchBar"></SearchBar>
        </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> 

这是VidePlayerController.xml的代码

<VideoPlayer class = "video"></VideoPlayer>
        <View class="videoInfoView" layout="vertical" backgroundColor="blue">
            <Label class="titleInfo"></Label>
            <View class = "infoLabel" layout="horizontal" backgroundColor="yellow">
                <Label class="dateInfo"></Label>
                <Label class="urlInfo"></Label>
            </View>>
        </View>

1 个答案:

答案 0 :(得分:0)

我认为您在VidePlayerController.xml中缺少标记,并且还在VidePlayerController中的View标记内添加了VideoPlayer标记。