WinJS AutoSuggestBox无法正常呈现

时间:2015-07-25 14:15:57

标签: javascript microsoft-metro winjs

我正在使用此链接第一个示例中的WinJS.UI.AutoSuggestBox:http://try.buildwinjs.com/#searchbox:simplelist1

我复制完全相同的代码,以确保我没有犯任何错误,但它仍然没有正确呈现。我不知道问题可能是什么。

PS:Data.animeList是default.js上定义的命名空间,它工作正常,我一直在其他页面上使用它。它是一个字符串数组,就像上面提到的例子中的字符串一样。使用示例中提供的数组导致了同样的事情。

以下是显示问题所在的图片(好吧,它没有渲染,因此您无法看到任何内容):http://i.imgur.com/e0VYWB5.png

以下是代码:



// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(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.
            WinJS.UI.processAll().then(function () {

                // Renders the anime list view.
                //var animeListView = document.getElementById("animeList");
                //animeListView.winControl.header = Renderer._animeListHeaderTemplate;
                //animeListView.winControl.itemDataSource = Data.animeListData.dataSource;
                //animeListView.winControl.itemTemplate = Renderer._animeListTemplate;
                //animeListView.winControl.layout = new WinJS.UI.GridLayout();
            });


        },

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

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

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

    var suggestionList = Data.animeList;

    function suggestionsRequestedHandler(eventObject) {
        var queryText = eventObject.detail.queryText,
        query = queryText.toLowerCase(),
        suggestionCollection = eventObject.detail.searchSuggestionCollection;
        if (queryText.length > 0) {
            for (var i = 0, len = suggestionList.length; i < len; i++) {
                if (suggestionList[i].substr(0, query.length).toLowerCase() === query) {
                    suggestionCollection.appendQuerySuggestion(suggestionList[i]);
                }
            }
        }
    };

    function querySubmittedHandler(eventObject) {
        var queryText = eventObject.detail.queryText;
        WinJS.log && WinJS.log(queryText, "sample", "status");
    };

    WinJS.Namespace.define("Sample", {
        suggestionsRequestedHandler: WinJS.UI.eventHandler(suggestionsRequestedHandler),
        querySubmittedHandler: WinJS.UI.eventHandler(querySubmittedHandler)
    });


})();
&#13;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>home</title>

    <link href="home.css" rel="stylesheet" />
    <script src="home.js"></script>
</head>
<body>
    <!-- Home page. -->
    <div class="fragment">

        <!-- Header of the home page. -->
        <header aria-label="Header content" role="banner">

            <!-- Back button for navigation between pages. -->
            <button data-win-control="WinJS.UI.BackButton"></button>

            <!-- Page title. -->
            <h1 class="titlearea win-type-ellipsis">Anime Manager</h1>

            <!-- Navbar. -->
            <div class="navbar">
                <button type="button">Profile</button>
                <button type="button">Settings</button>
              
                <!-- The AutoSuggestBox -->
                <div style="background: red; display: inline-block; margin: 15px 0;" data-win-control="WinJS.UI.AutoSuggestBox" data-win-options="{
                     placeholderText: 'Type a show',
                     onsuggestionsrequested: Sample.suggestionsRequestedHandler,
                     onquerysubmitted: Sample.querySubmittedHandler
                     }"></div>
                <!--<input type="search" placeholder="Search a show..." />-->
            </div>

        </header>

        <!-- Body of the home page. -->
        <section class="page-section" aria-label="Main content" role="main">
            <div id="testes"></div>

            <!-- Anime list view. -->
            <!--<div id="animeList" data-win-control="WinJS.UI.ListView" data-win-options="{header: select('.header')}"></div>-->
        </section>

    </div>
</body>
</html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

我发现了问题。我的WinJS已经过时了 - 我使用的是WinJS 3,这个功能适用于WinJS 4。