2015-05-30 21 views
0

林學建一個窗口在Visual Studio 8.1導航軟件表現2013年
從的PageControl犯規火ready事件Winjs導航

伊夫內部創建home.html的一個按鈕,並綁定一個click事件執行導航到pageControl元素稱爲htmlcontrols(導航工作正常)。接下來,我創建了一個名爲otherpage的新pageControl,並且我添加了另一個按鈕,但是這次是在htmlcontrols中。我將另一個單擊事件綁定到此按鈕以從htmlcontrols導航到其他頁面。

導航流程應該是:
家(點擊) - > htmlcontrols(點擊) - > otherpage

第二導航不工作,我已經試圖把一個調試器就緒事件中的otherpage .js但它不會觸發。
我完全失去了!

htmlcontrols.html:

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

    <link href="htmlcontrols.css" rel="stylesheet" /> 
    <script src="htmlcontrols.js"></script> 
</head> 
<body> 
    <div class="htmlcontrols fragment"> 
     <header class="page-header" aria-label="Header content" role="banner"> 
      <button class="back-button" data-win-control="WinJS.UI.BackButton"></button> 
      <h1 class="titlearea win-type-ellipsis"> 
       <span class="pagetitle">Welcome to htmlcontrols</span> 
      </h1> 
     </header> 
     <section class="page-section" aria-label="Main content" role="main"> 

      <button id="newButton">Link to another page!</button> 
     </section> 
    </div> 
</body> 
</html> 

htmlcontrols.js:

// For an introduction to the Page Control template, see the following documentation: 
// http://go.microsoft.com/fwlink/?LinkId=232511 
(function() { 
    "use strict"; 

    var nav = WinJS.Navigation; 

    WinJS.UI.Pages.define("/pages/htmlcontrols.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) { 
      // NEVER REACHES THIS POINT 
      debugger; 
      newButton.addEventListener("click", function (e) { 

       nav.navigate("/pages/otherpage/otherpage.html"); 
      }, false); 
     }, 

     unload: function() { 
      // TODO: Respond to navigations away from this page. 

     }, 

     updateLayout: function (element) { 
      /// <param name="element" domElement="true" /> 

      // TODO: Respond to changes in layout. 
     } 
    }); 
})(); 

回答

0

找到了! 在htmlcontrols.js中,WinJS.UI.Pages.define()中的uri是錯誤的。

0

我很高興你找到答案。更具體地說,頁面的.html文件在項目中的位置以及WinJS.UI.Pages.define 中的相對URI必須與匹配,才能正確關聯Page控件和HTML文件中的代碼。否則發生的事情是HTML加載得很好,但是當WinJS查找一個已定義的頁面控件時,它找不到匹配項,因此它不會觸發任何這些事件。

請注意,如果您將錯誤的URI提供給Navigator.navigate並且找不到該文件,則會引發異常。但是,在Pages.define中使用錯誤的UI不會拋出,因爲WinJS假定頁面可以在沒有事件處理程序的情況下正常運行。