IBM Worklight 6.1 - How to display a prompt dialog

2019-06-01 05:15发布

问题:

It was able to display a prompt box in common resources ("preview as common resources"), but it is not working in the Android Emualtor.

What is the reason?

回答1:

Have you tried using Cordova's navigator.prompt?

For example, in common\main.js:

function wlCommonInit() {
    navigator.notification.prompt(
        'Please enter your name',  // message
        onPrompt,                  // callback to invoke
        'Registration',            // title
        ['Ok','Exit'],             // buttonLabels
        'Jane Doe'                 // defaultText
    );
}

function onPrompt() {
    alert("prompted");
}

I tested this in iOS, but it will work in Android as well.

When previewing your application, use some stub or "regular" JS implementation, but for the mobile environments, use Cordova's.