2013-03-29 2 views
1

У меня есть приложение для навигации, и я хочу вызвать вторую страницу, которая будет загружена в default.html, чтобы выполнить функцию в готовом разделе.готовый обработчик Windows Store приложение с Javascript

Я написал в 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); 
      } 
     }); 
    } 

}); 

})();

Смежные вопросы