调试应用程序示例代码 (JavaScript)

本主题中的代码是快速入门:调试应用程序 (JavaScript)的示例文件。此版本的代码中修复了快速入门中有意出现的错误。

示例代码

快速入门中的 <body> 标记中使用了以下 HTML 代码。

    <div id="flipTemplate" data-win-control="WinJS.Binding.Template" 
             style="display:none">
        <div class="fixedItem" >
            <img data-win-bind="src:  flipImg" />
        </div>
    </div>
    <div  id="fView" style="width:100%;height:100%;background-color:#0094ff" 
        data-win-control="WinJS.UI.FlipView" data-win-options= "{ 
        itemDataSource: pages.dataSource, itemTemplate: flipTemplate }" >
    </div>

以下代码示例展示了 default.js 中的完整 JavaScript 代码。对此代码的 WinJS 命名空间的引用位于模板的 default.html 文件中。

(function () {
    "use strict";

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    var myData = [];
    for (var x = 0; x < 4; x++) {
        myData[x] = { flipImg: "/images/logo.png" }
    };

    var pages = new WinJS.Binding.List(myData, { proxy: true });

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !==
            activation.ApplicationExecutionState.terminated) {
                // TODO: . . .
            } else {
                // TODO: . . .
            }
            args.setPromise(WinJS.UI.processAll());

            updateImages();
        }
    };

    function updateImages() {

        pages.push(0, { flipImg: "https://go.microsoft.com/fwlink/?LinkID=223195" });
        pages.push(1, { flipImg: "https://go.microsoft.com/fwlink/?LinkID=223196" });
        pages.push(2, { flipImg: "https://go.microsoft.com/fwlink/?LinkID=223197" });
    };

    app.oncheckpoint = function (args) {
    };

    app.start();

    var publicMembers = {
        items: pages
    };

    WinJS.Namespace.define("Data", publicMembers);

})();