I'm implementing a DataAdapter to bind to a WinJS ListView control. That interface requires a getCount method which returns a Promise. If I return a WinJS.xhr object directly, that works fine. However, I want to massage the response of that before passing it back to the caller.
My problem is that if I return that same WinJS.xhr object, but tack a "then" at the end of it, which takes it's output and massages it, then the caller is not getting the expected output (things blow up in the bowels of the WinJS libraries).
So, I think I don't understand how to return a Promise that's nested in a Promise. Anyone know how to do this?
This is pretty straightforward once you figure it out.
Two things you need to know:
So, to do what you want to accomplish, it's be something like this:
return WinJS.xhr({url: whateverYourURlIs })
.then(function (response) {
var tweakedResponse = processResponse(response);
return tweakedResponse;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With