1

我将 Pase.com 与 js SDK 一起用于我的 Dart 应用程序的后端。除了 parse sdk 接受回调函数的对象之外,这很好用。在飞镖中我不确定如何做到这一点,我可以让单个回调正常工作。但我在这里完全迷失了。

用于注册用户的 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);
    }
  });

我的飞镖代码

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 天。

4

1 回答 1

4

代替 :

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}));
于 2013-03-13T22:42:23.970 回答