Nested Promises in WinJS

I am implementing a DataAdapter to bind to a WinJS ListView control. This interface requires the getCount method, which returns Promise. If I return the WinJS.xhr object directly, this works fine. However, I want to massage the reaction of this before passing it back to the caller.

My problem is that if I return the same WinJS.xhr object, but attach a “then” to it at the end of it, which displays and massages it, the caller does not get the expected result (things exploded in the bowels of the WinJS libraries).

So, I think I don’t understand how to return the promise enclosed in the promise. Does anyone know how to do this?

+3
source share
1 answer

, .

, :

  • . then() ,
  • , , .

, , , :

return WinJS.xhr({url: whateverYourURlIs })
    .then(function (response) {
        var tweakedResponse = processResponse(response);
        return tweakedResponse;
    });
+4