gpt4 book ai didi

javascript - WinJS AutoSuggestBox 无法正确呈现

转载 作者:行者123 更新时间:2023-11-28 00:02:52 27 4
gpt4 key购买 nike

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

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

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

这是显示问题所在的图像(嗯,它没有渲染,所以你看不到任何东西):/image/E3tgd.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)
});


})();
<!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>

最佳答案

我发现了问题。我的 WinJS 已经过时了 - 我正在使用 WinJS 3,此功能适用于 WinJS 4。

关于javascript - WinJS AutoSuggestBox 无法正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31627362/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com