0

我想在我的 Windows 8 应用程序中编写搜索合同。除了建议列表之外,基本上一切都可以正常工作。总是当我输入函数时,我应该在其中添加我的建议,我得到运行时错误 0x8000000e

我只是从示例中复制粘贴代码,唯一的区别是我从数据库中加载数据。

appModel.Search.SearchPane.getForCurrentView().onsuggestionsrequested = function (eventObject) {
    var queryText = eventObject.queryText, suggestionRequest = eventObject.request;
    var query = queryText.toLowerCase();
    var maxNumberOfSuggestions = 5;
    mkData.getWords(eventObject.queryText, maxNumberOfSuggestions, function (suggestionList) {
        for (var i = 0, len = suggestionList.length; i < len; i++) {
            if (suggestionList[i].substr(0, query.length).toLowerCase() === query) {
                suggestionRequest.searchSuggestionCollection.appendQuerySuggestion(suggestionList[i]);
                if (suggestionRequest.searchSuggestionCollection.size === maxNumberOfSuggestions) {
                    break;
                }
            }
        }
    });
    if (suggestionRequest.searchSuggestionCollection.size > 0) {
        WinJS.log && WinJS.log("Suggestions provided for query: " + queryText, "sample", "status");
    } else {
        WinJS.log && WinJS.log("No suggestions provided for query: " + queryText, "sample", "status");
    }
};

如果我用一个静态的建议数组交换 Ajax-Call,它就可以工作:( 在建议列表中是好词。

我已经找到了解决方案,但仅限于 C#。开发人员必须在那里添加 await 关键字,但在 javascript 中我没有这个。

提前致谢!

4

1 回答 1

0

好吧,我现在自己解决了。这里是解决方案。你必须使用延期。它几乎没有记录:(

appModel.Search.SearchPane.getForCurrentView().onsuggestionsrequested = function (eventObject) {
    var queryText = eventObject.queryText, suggestionRequest = eventObject.request;
    var maxNumberOfSuggestions = 5;
    var deferral = eventObject.request.getDeferral();
    mkData.getWords(queryText, maxNumberOfSuggestions, function (suggestionList) {
        suggestionRequest.searchSuggestionCollection.appendQuerySuggestions(suggestionList);
        deferral.complete();
    });
    if (suggestionRequest.searchSuggestionCollection.size > 0) {
        WinJS.log && WinJS.log("Suggestions provided for query: " + queryText, "sample", "status");
    } else {
        WinJS.log && WinJS.log("No suggestions provided for query: " + queryText, "sample", "status");
    }
};
于 2012-10-24T08:21:23.570 回答