vs11 express javascript 显示rss信息


效果如下:


做法:1.navigator app project(javascript)

2.homepage.html上输入:

 <h1>The Old New Thing</h1>
              <div id="downloadStatus"></div>
              <div id="posts"></div>

3.default.css上输入样式:

/* default.css */
body
{
    background-color: #fff;
    color: #000;
    font-family: Verdana;
    padding: 8pt;
}

a:link, a:visited, a:active
{
    color: #700;
    font-weight: inherit;
}

h1
{
    text-transform: none;
    font-family: inherit;
    font-size: 22pt;
}

#posts
{
    width: 99%;
    height: 100%;
    overflow: auto;
}

.postTitle
{
    color: #700;
    font-size: 1.2em;
    font-weight: bold;
}

.postDate
{
    color: #666;
    font-size: 11pt;
}

.postContent
{
    font-size: medium;
    line-height: 18px;
}


4.在homepage.js上对id进行映射:

   downloadStatus.innerText = "downloading posts...";
            WinJS.xhr({ url: "http://blogs.msdn.com/b/oldnewthing/rss.aspx" }).
            then(processPosts, downloadError);


在构造函数中添加好上面的代码,记得对当中的一些函数添加代码:

    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);
        }
    }

    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";
    }

如此便可从msdn blog上获得rss订阅信息





拓展:显示list布局的信息

1.在homepage.js中替换掉processPost函数

 var 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
        posts.winControl.dataSource = postItems;
    }


2.homepage。html中设置布局

<body>
    <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>
</body>

如下便能出现list布局的页面




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值