代码之家  ›  专栏  ›  技术社区  ›  Giulia Marra

如何使用返回承诺的外部方法?(JavaScript)

  •  1
  • Giulia Marra  · 技术社区  · 8 年前

    我正在从ionic 2(BLE)的本机插件调用一个函数: IsEnabled()

    在BLEscanner中。js公司

          blEnabled() {
           BLE.isEnabled();
           return Promise;
          }
    

    在家里。js公司

        var BLicon {
         iconColor = function () {
           if (BLEscanner.blEnabled().Promise.isFulfilled())
            return '#606060'; //the icon displayed is gray
    
           else return '#030303';
         };
         msg = function () {
          if (BLEscanner.blEnabled().Promise.isFulfilled())
            return "Bluetooth is ON";
    
          else return "Bluetooth is OFF";
          }
        }
    

    我要用 msg 将在操作警报中键入图标。但我不知道如何使用/开发 isFulfilled() 命令

    1 回复  |  直到 8 年前
        1
  •  1
  •   Rohit Agrawal    8 年前

    BLE。isEnabled()返回承诺:

     blEnabled() {
           return BLE.isEnabled();//Returns a promise
     }
    

    BLEscanner.blEnabled().then(() => {
        //success
        iconColor = '#606060';
        msg = "Bluetooth is ON";
    }, () =>{
        //fail
        iconColor = '#030303';
        msg = "Bluetooth is OFF";
    });