2012-09-21 18 views
1

我想添加關於按鈕(可能是鏈接)到設置魅力。 但我不想在設置的魅力顯示內容,我需要瀏覽應用程序中的About.html頁面。 應用程序設置示例沒有幫助我。無論如何要實現這一目標? 我需要JavaScript和HTML要做到這一點;)將關於按鈕添加到設置魅力

目前我添加下面的代碼到default.js

app.onactivated = function (eventObject) { 
     if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { 
      //WinJS.UI.disableAnimations(); 

      WinJS.Application.onsettings = function (e) { 
       e.detail.applicationcommands = { 
        "about": { 
         title: "About", href:"/html/About.html" 
         } 
       } 
       WinJS.UI.SettingsFlyout.populateSettings(e); 
       }; 
... 
} 

我創建的HTML文件夾下的HTML文件。下面是About.html

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

    <!-- WinJS references --> 
    <script src="//Microsoft.WinJS.1.0/js/base.js"></script> 
    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script> 


    <link rel="stylesheet" type="text/css" href="css/staticPages.css" /> 
    <script type="text/javascript" src="/js/navigator.js"></script> 
    <script src="/js/jq-1.7.1.min.js" type="text/javascript"></script> 
    <script type="text/javascript" src="/js/networkInfo.js"></script> 
    <script src="/js/About.js" type="text/javascript"></script> 
</head> 
    <body> 
    <div id="siluet" class="siluet">&nbsp;</div> 
    <div id="contentDetay"> 
     <button id="backbutton" class="win-backbutton"> 
     </button> 
     <img id="headLogo" src="/images/head_logo.png" alt="XYZ" /> 
     <progress id="progressRing"></progress> 
     <div id="title"><h1 id="groupNameHeader">Group Name</h1><h1 id="pageTitle">Page Title</h1><div id="sectionSelectArrow">&nbsp;</div></div> 
     <div id="menuPopUp"> 
      <select id="menuList" multiple="multiple"></select> 
     </div> 

     <div id="staticContainer"></div> 
     <div id="noSnapView"> 
      <p>İçeriği görüntüleyebilmek için ekranı büyütün</p> 
     </div> 
    </div> 
</body> 

</html> 

當我點擊關於下設置的魅力吧鏈接的問題的代碼,我在About.js文件,該文件是在/ JS文件夾中遇到錯誤。

(function() { 
    'use strict'; 

    var dataItems; 
    var groupIndex; 
    var sectionIndex; 
    var itemIndex; 

    function ready(element, options) { 

     networkInfo.getInfo(); 
     pageTitle.style.display = "none"; // pageTitle.style is undefined 

     var that = this; 
     groupNameHeader.innerText = "About"; // groupNameHeader is undefined 

     var aboutContent; // This content is retrieving from web service 
     // staticContainer is undefined 
     staticContainer.innerHTML = window.toStaticHTML(aboutContent); 

    } 

    WinJS.Namespace.define("appGlobal", { 
     fadeProgressRingOut: fadeProgressRingOut 
    }); 
    WinJS.UI.Pages.define("/html/About.html", { 
     ready: ready 
    }); 

})(); 

正如您可以看到每個HTML元素在.js文件中未定義;但我找不到原因。

回答

2

改變這樣的代碼可以解決您的問題:

app.onactivated = function (eventObject) { 
    if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) { 
     //WinJS.UI.disableAnimations(); 

     var settingsPane = Windows.UI.ApplicationSettings.SettingsPane.getForCurrentView(); 
     settingsPane.addEventListener("commandsrequested", onCommandsRequested); 

    // ... 

} 

function onSettingsCommand(){ 
    nav.navigate("html/about.html"); 
} 

function onCommandsRequested(eventArgs){ 
    var settingsCommand = new Windows.UI.ApplicationSettings.SettingsCommand("about", About", onSettingsCommand); 
    eventArgs.request.applicationCommands.append(settingsCommand); 
} 
3

JavaScript App Settings sample顯示如何添加一個按鈕到設置的魅力非常詳細。

這裏是一個片段,讓你開始:

WinJS.Application.onsettings = function (e) { 
    e.detail.applicationcommands = { 
     "aboutDiv": { title: "About", href: "/html/About.html" } 
    }; 
    WinJS.UI.SettingsFlyout.populateSettings(e); 
}; 
+0

是的,我已經找到了這個代碼,但我不能工作了。這很奇怪,因爲調用了about.html的.js文件(about.js),但無法從.js文件訪問html元素。每個控件的值都是未定義的。 –