如何在windows8 metro app中创建list界面

1.ui 设计:

    <h1>The Old New Thing</h1>
            <div id="downloadStatus"></div>
            <div id="template" data-win-control="WinJS.Binding.Template">
                <div data-win-bind="innerText: title" class="postTitle"></div>
                <div data-win-bind="innerText: date" class="postDate"></div>
            </div>
            <div id="posts" data-win-control="WinJS.UI.ListView"
                 data-win-options="{itemRenderer: template, layout: {type: WinJS.UI.ListLayout}}"></div>

2.function 设计:

    var postItems = [];

    function processPosts(request) {
        // clear the progress indicator
        downloadStatus.innerText = "";

        // parse the RSS
        var items = request.responseXML.selectNodes("//item");
        if (items.length == 0) { downloadStatus.innerText = "error downloading posts"; }

        for (var i = 0, len = items.length; i < len; i++) {
            var item = items[i];
            // append data to #posts div
            //var parent = document.createElement("div");
            //appendDiv(parent, item.selectNodes("title")[0].text, "postTitle");
            //appendDiv(parent, item.selectNodes("pubDate")[0].text, "postDate");
            //appendDiv(parent, item.selectNodes("description")[0].text, "postContent");
            posts.appendChild(parent);
            WinJS.Utilities.setInnerHTMLUnsafe(posts, parent);
            //msWWA.execUnsafeLocalFunction(function () { posts.appendChild(parent); });

            var post = {
                title: item.selectNodes("title")[0].text,
                date: item.selectNodes("pubDate")[0].text,
                content: item.selectNodes("description")[0].text,
            };
            postItems.push(post);

        }

        posts.winControl.dataSource = postItems;
    }



    //function processPosts(feed) {
    //    downloadStatus.innerText = "";

    //    for (var i = 0, len = feed.items.length; i < len; i++) {
    //        var item = feed.items[i];
    //        var post = {
    //            title: item.title.text,
    //            date: item.publishedDate,
    //            content: item.summary.text,
    //        };
    //        postItems.push(post);
    //    }

    //    // populate the ListView control's data source
        
    //    msWWA.execUnsafeLocalFunction(function () { posts.winControl.dataSource = postItems; });
    //}




    function appendDiv(parent, html, className) {
        var div = document.createElement("div");
        div.innerHTML = html;
        div.className = className;
        parent.appendChild(div);
    }

    function downloadError() {
        downloadStatus.innerText = "error downloading posts";
    }

3.使用:

function fragmentLoad(elements, options) {
        WinJS.UI.processAll(elements)
            .then(function () {
            // TODO: Initialize the fragment here.
            downloadStatus.innerText = "downloading posts...";
            WinJS.xhr({ url: "http://blogs.msdn.com/b/oldnewthing/rss.aspx" }).
            then(processPosts, downloadError);

            //var md = new Windows.UI.Popups.MessageDialog("Hello World");
            md.commands.append(new Windows.UI.Popups.UICommand("Yes"));
            md.commands.append(new Windows.UI.Popups.UICommand("No"));
            //md.showAsync().then(function (command){ alert("pressed"); });


        });
    }

效果:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值