调用onsuggestionsrequested(win8)时出现0x8000000e错误

时间:2012-10-24 08:05:26

标签: javascript search windows-8 microsoft-metro

我想在我的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我没有这个。

提前感谢!

1 个答案:

答案 0 :(得分: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");
    }
};