2013-03-29 171 views
1

我有一个导航应用程序,并且我想要导致第二页将被加载到default.html以执行准备部分中的功能。准备好处理程序使用Javascript的Windows应用商店应用程序

我已经写在home.js下面的代码:

(function() { 
    "use strict"; 

    WinJS.UI.Pages.define("/pages/home/home.html", { 
     // This function is called whenever a user navigates to this page. It 
     // populates the page elements with the app's data. 
     ready: function (element, options) { 
      // TODO: Initialize the page here. 

      var articlesList; 

      articlesList = new WinJS.Binding.List(); 
      var publicMembers = { ItemList: articlesList }; 
      WinJS.Namespace.define("DNZ", publicMembers); 



     }, 

     RSSFeedHandler: function getRssFeed() { 
      WinJS.xhr({ url: "http://feeds.feedburner.com/dotnetzone?format=xml" }).then(function (rss) { 
       var items = rss.responseXML.querySelectorAll("item"); 

       for (var n = 0; n < items.length; n++) { 
        var article = {}; 
        article.title = items[n].querySelector("title").textContent; 
        article.link = items[n].querySelector("link").textContent; 
        article.description = items[n].querySelector("description").textContent; 
        article.pubDate = items[n].querySelector("pubDate").textContent; 
        articlesList.push(article); 
       } 
      }); 
     } 

    }); 
})(); 

但是这使得它运行调试器时的问题;并停止。

home.html页面包含以下标签:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <title>homePage</title> 

    <!-- WinJS references --> 
    <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" /> 
    <script src="//Microsoft.WinJS.1.0/js/base.js"></script> 
    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script> 

    <link href="/css/default.css" rel="stylesheet" /> 
    <link href="/pages/home/home.css" rel="stylesheet" /> 
    <script src="/pages/home/home.js"></script> 
</head> 
<body> 
    <!-- The content that will be loaded and displayed. --> 
    <div class="fragment homepage"> 
     <div id="main"> 
      <div id="DNZItemTemplate" data-win-control="WinJS.Binding.Template" style="display: none;"> 
       <div class="listItemTemplate" style="width: 173px; height: 100px;"> 
        <div class="listItemTitle" data-win-bind="innerText: title" style="width: 173px; height: 100px;"></div> 
        <div class="listItemImage" data-win-bind="innerText: pubDate" style="width: 173px; height: 100px;"></div> 
        <!--<div class="listItemTitle" data-win-bind="innerText: link"> 
        </div>--> 
       </div> 
      </div> 
      <header aria-label="Header content" role="banner"> 
       <button class="win-backbutton" aria-label="Back" disabled type="button"></button> 
       <h1 class="titlearea win-type-ellipsis"> 
        <span class="pagetitle">Καλως ήρθατε!</span> 
       </h1> 
      </header> 
      <section aria-label="Main content" role="main"> 
       <section id="content"> 
        <div id="articlelist" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource: DNZ.ItemList.dataSource, itemTemplate: DNZItemTemplate }"></div> 
       </section> 
      </section> 
      </div> 
    </div> 
</body> 
</html> 

,我认为这个问题是,当我试图把项目列表视图!你有没有任何想法,我必须编写它来运行getRSSFeed函数,当加载home.html

回答

1

为了使articlesList是在RSSFeedHndler方法可见,你需要使它的页面对象的属性如下:

(function() { 
"use strict"; 

WinJS.UI.Pages.define("/pages/home/home.html", { 
    articlesList:null, 
    // This function is called whenever a user navigates to this page. It 
    // populates the page elements with the app's data. 
    ready: function (element, options) { 
     // TODO: Initialize the page here. 

     // var articlesList; 
     this.articlesList = new WinJS.Binding.List(); 

     var publicMembers = { ItemList: articlesList }; 
     WinJS.Namespace.define("DNZ", publicMembers); 
    }, 

    RSSFeedHandler: function getRssFeed() { 
     var _this=this; 
     WinJS.xhr({ url: "http://feeds.feedburner.com/dotnetzone?format=xml" }).then(function (rss) { 
      var items = rss.responseXML.querySelectorAll("item"); 

      for (var n = 0; n < items.length; n++) { 
       var article = {}; 
       article.title = items[n].querySelector("title").textContent; 
       article.link = items[n].querySelector("link").textContent; 
       article.description = items[n].querySelector("description").textContent; 
       article.pubDate = items[n].querySelector("pubDate").textContent; 
       _this.articlesList.push(article); 
      } 
     }); 
    } 

}); 

})();

相关问题