飞镖JS互操作 - 如何通过功能的回调对象(Dart JS Interop - How to pas

2019-09-26 11:32发布

我使用Pase.com与我的飞镖应用程序的后台JS SDK。 这个工作从剖析SDK天晴接受的回调函数的对象。 在省道林不确定如何做到这一点,我可以得到一个回调正常工作。 但是我在这里完全丧失。

正常解析JS用于注册用户

var user = new Parse.User();
  user.set("username", "my name");
  user.set("password", "my pass");
  user.set("email", "email@example.com");

  // other fields can be set just like with Parse.Object
  user.set("phone", "415-392-0202");

  user.signUp(null, {
    success: function(user) {
      // Hooray! Let them use the app now.
    },
    error: function(user, error) {
      // Show the error message somewhere and let the user try again.
      alert("Error: " + error.code + " " + error.message);
    }
  });

我的飞镖代码

void registerSuccess(user) {
    print("success");
  }

  void registerFailed(user, error){
    print("fail");
  }

  void register(String email, String password)
  {
    js.scoped(() {

      var parse = js.context.Parse;


      var parseUser = new js.Proxy(parse.User);

      parseUser.set("username", "my name");
      parseUser.set("password", "my pass");
      parseUser.set("email", "email@example.com");

      print(parseUser.getEmail());

      var callbackSuccess = new js.Callback.once(() => registerSuccess());
      var callbackFailed = new js.Callback.once(() => registerFailed());

      parseUser.signUp(null,{"success":callbackSuccess, "error": callbackFailed});

      //parseUser.signUp();
    });
  }

此外回调函数需要接受来自JS传回瓦尔。

任何帮助,将一个认识,我已经被纺纱我的车轮上这2天。

Answer 1:

代替 :

var callbackSuccess = new js.Callback.once(() => registerSuccess());
var callbackFailed = new js.Callback.once(() => registerFailed());
parseUser.signUp(null,{"success":callbackSuccess, "error": callbackFailed});

采用 :

var callbackSuccess = new js.Callback.once(registerSuccess);
var callbackFailed = new js.Callback.once(registerFailed);
parseUser.signUp(null, js.map({"success":callbackSuccess, "error": callbackFailed}));


文章来源: Dart JS Interop - How to pass a callback object of functions
标签: dart