如何连续打印 2 个警报 WinJS [英] how to print 2 alerts consecutives WinJS

查看:16
本文介绍了如何连续打印 2 个警报 WinJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序上打印两个警报,一个用于显示应用程序,在第一个警报上按下关闭按钮以显示第二个警报

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

推荐答案

您不能同时打开多个 MessageDialog.由于 showAsync 立即返回(异步参考),你的代码需要等到它关闭.

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.

要做到这一点,您需要依赖 showAsync 返回的 Promise:

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()
    });

上面,代码等待 done 回调在 Promise 上被调用,然后显示第二个对话框.

Above, the code waits for the done callback to be called on the Promise and then shows a second dialog.

这篇关于如何连续打印 2 个警报 WinJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆