SearchPaneSuggestionsRequestDeferral class

SearchPaneSuggestionsRequestDeferral class

Enables the app to signal when it has finished populating a searchSuggestionCollection object while handling the suggestionsrequested event. Apps should use a deferral if and only if they need to respond to a request for suggestions asynchronously.

Syntax


var searchPaneSuggestionsRequestDeferral = searchPaneSuggestionsRequest.GetDeferral();

Members

The SearchPaneSuggestionsRequestDeferral class has these types of members:

Methods

The SearchPaneSuggestionsRequestDeferral class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Complete Signals that the app has finished populating a searchSuggestionCollection object while handling the suggestionsrequested event.

 

Remarks

Your app should respond asynchronously to a request for suggestions if fulfilling the request will take a significant amount of time, such as fetching suggestions from a web service.

Use the searchPaneSuggestionsRequestDeferral.complete method to signal when your app has fulfilled the request.

An app retrieves this object by calling the searchPaneSuggestionsRequest.getDeferral method while handling the suggestionsrequested event.

Examples

The Search contract sample demonstrates how to respond to a suggestionsrequested event, including how to get a deferral.


Windows.ApplicationModel.Search.SearchPane.getForCurrentView().onsuggestionsrequested = function (eventObject) {
    var queryText = eventObject.queryText, language = eventObject.language, suggestionRequest = eventObject.request;

    // The deferral object is used to supply suggestions asynchronously for example when fetching suggestions from a web service.
    // Indicate that we'll do this asynchronously:
    var deferral = suggestionRequest.getDeferral();

    // Use the web service Uri entered in the urlInput that supports this standard in order to see suggestions come from the web service.
    // See http://msdn.microsoft.com/en-us/library/cc848863(v=vs.85).aspx for details on XML Search Suggestions format.
    // And replace "{searchTerms}" with the query string, which should be encoded into the URI.
    var suggestionUri = document.getElementById("urlInput").innerText.replace("{searchTerms}", encodeURIComponent(queryText));

    // Cancel the previous suggestion request if it is not finished.
    if (xhrRequest && xhrRequest.cancel) {
        xhrRequest.cancel();
    }

    // Create request to obtain suggestions from service and supply them to the Search Pane.
    xhrRequest = WinJS.xhr({ url: suggestionUri });
    xhrRequest.done(
        function (request) {
            if (request.responseXML) {
                generateSuggestions(request.responseXML, suggestionRequest.searchSuggestionCollection, queryText);
            }

            deferral.complete(); // Indicate we're done supplying suggestions.
        },
        function (error) {
            WinJS.log && WinJS.log("Error retrieving suggestions for query: " + queryText, "sample", "status");

            // Call complete on the deferral when there is an error.
            deferral.complete();
        });
};


Requirements (Windows 10 device family)

Device family

Desktop, introduced version 10.0.10240.0
Xbox, introduced version 10.0.10586.0

API contract

Windows.ApplicationModel.Search.SearchContract, introduced version 1.0

Namespace

Windows.ApplicationModel.Search
Windows::ApplicationModel::Search [C++]

Metadata

Windows.ApplicationModel.Search.SearchContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported

Namespace

Windows.ApplicationModel.Search
Windows::ApplicationModel::Search [C++]

Metadata

Windows.winmd

Attributes

[Deprecated()]
[MarshalingBehavior(Agile)]
[Version(0x06020000)]

See also

Object
Reference
SearchPane class
SearchPane.SuggestionsRequested event
SearchPaneSuggestionsRequest class
SearchPaneSuggestionsRequest.GetDeferral method
SearchPaneSuggestionsRequestedEventArgs class

 

 

Show:
© 2017 Microsoft