IBM Worklight - 如何自定义connectOnStartup故障对话框

时间:2014-04-09 21:13:23

标签: ibm-mobilefirst worklight-runtime

可以自定义在设置connectOnStartup = true时弹出的错误警报。我不希望我的用户从该警报中单击“详细信息”并查看错误消息的详细信息。我希望使用自定义消息和操作自定义该警报。

enter image description here

1 个答案:

答案 0 :(得分:2)

两个选项:

  1. 除了在initOptions.js中使用connectOnStartup属性外,还要使用onConnectionFailure属性:

    var wlInitOptions = {
        connectOnStartup : true,
    
        // # The callback function to invoke in case application fails to connect to Worklight Server
        onConnectionFailure: function () { 
            WL.SimpleDialog.show(
                "foo",
                "bar",
                [{text: "button",
                 handler : function() {alert("button pressed");}
                }]
             );
            // optionally add more logic here
        },
        ...
        ...
    
  2. 请勿使用connectOnStartup属性。相反,请在适当时使用WL.Client.connect连接到服务器。例如,在wlCommonInit()

    function wlCommonInit() { 
        WL.Client.connect({ onSuccess: success, onFailure: failure});
    }
    
    function success() {
        // ...
    }
    
    function failure() {
        WL.SimpleDialog.show(
            "foo",
            "bar",
            [{text: "button",
              handler : function() {alert("button pressed");}
            }]
       );
        // optionally add more logic here
    }