YUI3 datasource-polling模块

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<ol id="issues"></ol>
<script src="http://yui.yahooapis.com/3.16.0/build/yui/yui-min.js"></script>
<script type="text/javascript">

YUI().use('datasource-local', 'datasource-polling', 'node-base', function(Y) {

    var src = [
        {'id': 0001, 'html_url': '#', 'title': 'liangxinglei'},
        {'id': 0002, 'html_url': '#', 'title': 'shiyongshan'},
        {'id': 0003, 'html_url': '#', 'title': 'lianghaowen'}
    ],
    dataSource = new Y.DataSource.Local({source: src}),
    ol = Y.one('#issues');

    var requestConfig = {
        on: {
            success: function(rsp) {
                var issues = rsp.response.results,
                        template = '<li><a href="{html_url}">{id}</a>{title}</li>';
                Y.Array.each(issues, function(issue) {
                    ol.append(Y.Lang.sub(template, issue));
                });
            }
        }
    }
    // dataSource.sendRequest();

    var transactionId = dataSource.setInterval(5000, requestConfig);
});
</script>
</body>
</html>

 

posted @ 2014-06-12 10:21  wheats  阅读(155)  评论(0编辑  收藏  举报