简体   繁体   English

Dart JS Interop - 如何传递函数的回调对象

[英]Dart JS Interop - How to pass a callback object of functions

I am using Pase.com with js SDK for the backend of my Dart App. 我正在使用Pase.com和js SDK作为我的Dart App的后端。 This works fine apart from the parse sdk accepts an object of callback functions. 除了解析sdk接受回调函数的对象之外,这个工作正常。 In dart Im unsure how to do this, I can get single callbacks working fine. 在飞镖中我不确定如何做到这一点,我可以让单个回调工作正常。 But Im completely lost here. 但我完全迷失在这里。

Normal Parse JS for registering a user Normal Parse 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);
    }
  });

My Dart code 我的Dart代码

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();
    });
  }

Also the callback function needs accept vars passed back from the js. 回调函数还需要从js传回的接受变量。

Any help would be a appreciated, I have be spinning my wheels for 2 days on this. 任何帮助将是一个赞赏,我已经在我的车轮旋转了2天。

Instead of : 代替 :

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

use : 采用 :

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM