我想在我的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我没有这个。
提前感谢!
答案 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");
}
};