如何在Tizen上使用caph列表的更新功能?

时间:2018-01-18 17:48:58

标签: jquery tizen samsung-smart-tv caph-framework

我遵循此处的文档:http://developer.samsung.com/onlinedocs/tv/caphdocs/main.html?type=jquery&doc=tutorial&p1=8

我在contentList.html文件中有这个:

    <div class="list-container">
        <div id="list1"></div> 
    </div>

在我的contentList.js文件中,在window.onLoad函数中,我有以下内容:

$('#list1').caphList({
        items: listOfSeries,
        template: '<div class="item" focusable><div style= "width:100%; height:100%"></div><%= item.title %></div>',
        containerClass : 'list',
        direction: 'vertical'
    });
var contentListView = $('#list1')[0].caphList;

其中listOfSeries是一个定义为空数组的全局变量。我有一个按钮,当按下该按钮时,向服务器发送GET请求以获取电视节目系列列表。然后,一旦我填充了listOfSeries,我就想通过调用contentListView.update()来更新列表。但是,我收到一个错误说:

无法读取属性&#39;更新&#39;未定义的。

我对网络开发还比较陌生,所以如果这是一个菜鸟问题,我很抱歉,但如何更新此内容列表呢?

编辑:

这是我的contentList.js文件

var globalUrl = "";
var contentListRequestAttempts;
var listOfSeries = [""];

window.onload = function () {

    /*$(".contentListButton").caphButton({
        onFocused : function(event, originalEvent){
            $(event.currentTarget).css({
                "border" : "3px solid red",
                "height" : "50px",
                "font-size" : "40px"
            });
        },
        onBlurred : function(event, originalEvent){
            $(event.currentTarget).css({
                "border" : "3px solid transparent",
                "height" : "50px",
                "font-size" : "40px"
            });
        },
        focusOption: {

        },
        toggle : false,
        onSelected : function(event, originalEvent){
            contentListRequestAttempts = 0;
            requestContentList();
        }
    }); */


    $('#list1').caphList({
        items: listOfSeries,
        template: '<div class="item" focusable><div style= "width:100%; height:100%"></div><%= item.title %></div>',
        containerClass : 'list',
        direction: 'vertical'
    });
    var contentListView = $('#list1')[0].caphList;
    contentListRequestAttempts = 0;
    requestContentList(contentListView);

}

function requestContentList(contentListView){
    console.log("Send Content List Request- Attempt#"+contentListRequestAttempts);
    globalUrl = localStorage.getItem("serverUrl");
    var getContentListUrl = globalUrl + "/client/v1/content";

    console.log("Get content list url:" + getContentListUrl);

    $.ajax({
        url: getContentListUrl,
        type: 'GET',
        success: function(result){
            var parsed = JSON.parse(result);
            console.log(parsed);

            var numberOfSeries = parsed.DfwWebClient.recordings.length;

            // Check if response contains recordings up to 10 times
            if(contentListRequestAttempts < 10){
                if(numberOfSeries === 0){
                    //If content list is not ready yet, wait half sec before requesting content list again
                    contentListRequestAttempts++;
                    wait(500);
                    requestContentList();
                } else {                
                    parseRecordings(parsed, contentListView);
                }       
            } else {
                alert("No Content Found");
            }               
        },
        error: function(xhr,status,error){
            alert("Server not found. Please ensure server is enabled, and that the IP address entered is correct.");
        }
    }); 
}

function parseRecordings(jsonResponse,contentListView){
    var numberOfSeries = jsonResponse.DfwWebClient.recordings.length;
    console.log("Number of Series: "+numberOfSeries);

    listOfSeries= new Array(numberOfSeries);
    var i;
    for(i=0; i < numberOfSeries; i++){
        listOfSeries[i] = jsonResponse.DfwWebClient.recordings[i];
    }
    console.log(listOfSeries);

    /*var items = listOfSeries;*/

/*  $('#list1').caphList({
        items: listOfSeries,
        template: '<div class="item" focusable><div style= "width:100%; height:100%"></div><%= item.title %></div>',
        containerClass : 'list',
        direction: 'vertical',
        onFocusItemView: function(context) {
            //console.log('focus', context);
        }
    });*/

    //contentListView.reload();
    contentListView.update();
}

function wait(ms){
    var start = new Date().getTime();
    var end = start;
    while (end < start + ms){
        end = new Date().getTime();
    }
}

0 个答案:

没有答案