Bootbox 4.1.0: 如何将本地化字符串(如“确定”、“取消”)传递给 Bootbox 的确认框?

14
在 Bootbox 3.2.0 版本中,我能够使用如下方式传递字符串来进行确认操作:
bootbox.confirm(
    confirm_string, 
    cancel_string, 
    yes_string,
    function(r) {           
        if (r) {
            //do something
        }
    }
);

我正在升级到4.1.0版本,并且在上述函数调用中遇到了错误。

根据 Bootbox 4.1.0 的文档(http://bootboxjs.com/documentation.html),有两种调用确认对话框的方式:

bootbox.confirm(str message, fn callback)    
bootbox.confirm(object options)

我用信息字符串和回调函数测试了第一种方式,它是可行的。对于第二种方式,我能够按照以下方式传递一个对象:

{
  message: message_string
  callback: function(r) {
    //do something
  }
}

我该如何在第二种方式中传递确定和取消按钮的字符串?

谢谢和问候。


有没有人知道如何传递本地化字符串以用于“确定”和“取消”按钮? - curious1
3个回答

18

作为替代方案,也可以直接使用 bootbox.confirm 来完成,例如:

bootbox.confirm({
    buttons: {
        confirm: {
            label: 'Localized confirm text',
            className: 'confirm-button-class'
        },
        cancel: {
            label: 'Localized cancel text',
            className: 'cancel-button-class'
        }
    },
    message: 'Your message',
    callback: function(result) {
        console.log(result);
    },
    title: "You can also add a title",
});

9

或使用本地化选项来更改所有按钮的默认设置:

    bootbox.setDefaults({
          /**
           * @optional String
           * @default: en
           * which locale settings to use to translate the three
           * standard button labels: OK, CONFIRM, CANCEL
           */
          locale: "de"
    });

查看:http://bootboxjs.com/documentation.html,“助手方法”


7
您可以使用“自定义对话框”(bootbox.dialog)更改这些字符串。
bootbox.dialog({
  message: "Custom message",
  title: "Custom title",
  buttons: {
    danger: {
      label: "Custom Cancel",
      className: "btn-danger",
      callback: function() {
        //do something
      }
    },
    main: {
      label: "Custom OK",
      className: "btn-primary",
      callback: function() {
        //do something else
      }
    }
  }
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接