问题
I want to print two alerts on my app, one to show an application and after pressing close button on first alert to show the second alert
Windows.UI.Popups.MessageDialog("Hello Welcome").showAsync();
Windows.UI.Popups.MessageDialog("Welcome to my app").showAsync();
if I just print an alert, everything works good but on the other scenary (two alerts) the code stops with an error, how to fix that??
回答1:
You can't have multiple MessageDialog
s open at the same time. Since the showAsync
returns immediately (async reference), your code needs to wait until it's closed.
To do that you'd need to rely on the Promise
returned by showAsync
:
Windows.UI.Popups.MessageDialog("Hello Welcome")
.showAsync().done(function() {
Windows.UI.Popups.MessageDialog("Welcome to my app").showAsync()
});
Above, the code waits for the done
callback to be called on the Promise
and then shows a second dialog.
来源:https://stackoverflow.com/questions/20532134/how-to-print-2-alerts-consecutives-winjs