how to print 2 alerts consecutives WinJS

坚强是说给别人听的谎言 提交于 2020-01-05 01:35:44

问题


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 MessageDialogs 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!