加载中...

1.6.3 modal


Summary

A series of modal dialog api like toast, alert, confirm and prompt.

API

toast(options)

Arguments

  • options(object): some options.
    • message(string): the message that the toast shows.
    • duration(number): the duration(seconds) that the toast shows.
Example
  1. var modal = require('@weex-module/modal');
  2. modal.toast({'message': 'I am toast!', 'duration': 1});

alert(options, callback)

Arguments

  • options(object): some options.
    • message(string): the message that the alert shows.
    • okTitle(string): the title of alert button, default is OK.
  • callback(function): callback when complete.

Example

  1. var arg1 = 'I am alert!';
  2. var arg2 = 'I am ok';
  3. var modal = require('@weex-module/modal');
  4. modal.alert({
  5. message: arg1,
  6. okTitle: arg2
  7. }, function() {
  8. // TODO after the alert is complete.
  9. })

confirm(options, callback)

Arguments

  • options(object): some options.
    • message(string): the message that the confirm shows.
    • okTitle(string): the title of confirm button, default is 'OK'.
    • cancelTitle(string): the title of cancel button, default is 'Cancel'.
  • callback(function): callback when complete.

This method has a callback function whose arguments will be:

  • result(string): the title of the button that clicked by user.

Example

  1. var arg1 = 'I am alert!'
  2. var arg2 = 'I am ok'
  3. var arg3 = 'I am cancel'
  4. var modal = require('@weex-module/modal');
  5. modal.confirm({
  6. message: arg1,
  7. okTitle: arg2,
  8. cancelTitle: arg3
  9. }, function(result) {
  10. nativeLog(result)
  11. // TODO after the confirm is complete.
  12. });

prompt(options, callback)

Arguments

  • options(object): some options.
    • message(string): the message that the prompt shows.
    • okTitle(string): the title of confirm button, default is 'OK'.
    • cancelTitle(string): the title of cancel button, default is 'Cancel'.
  • callback(function): callback when complete.

This method has a callback function whose arguments will be:

  • res(object): the argument will be a object, which has attributes result and data, like { result: 'OK', data: 'hello world' }
    • result(string): the title of the button that clicked by user.
    • data(string): the value of the text that entered by user.

Example

  1. var arg1 = 'I am prompt!'
  2. var arg2 = 'I am ok'
  3. var arg3 = 'I am cancel'
  4. var modal = require('@weex-module/modal');
  5. modal.prompt({
  6. message: arg1,
  7. okTitle: arg2,
  8. cancelTitle: arg3
  9. }, function(res) {
  10. nativeLog(res.result + ', ' + res.data);
  11. // TODO after the prompt is complete.
  12. });

还没有评论.