1
我正在使用Pase.com和js SDK作为我的Dart App的后端。除了解析sdk接受回调函数的对象之外,这工作正常。在飞镖林不知道如何做到这一点,我可以得到单个回调工作正常。但我完全失去了这里。Dart JS Interop - 如何传递函数的回调对象
正常解析JS的注册用户
var user = new Parse.User();
user.set("username", "my name");
user.set("password", "my pass");
user.set("email", "[email protected]");
// 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);
}
});
我的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 protected]");
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天在此上。
查阅即时得到 未捕获的类 '()=>空隙' 没有实例方法 '呼叫'。 NoSuchMethodError:找不到方法:'call' Receiver:Closure :(动态)=>无效函数'registerFailed':. 参数:[Proxy'的实例,'Proxy'的实例,'Proxy'的实例] – user2166822 2013-03-14 04:05:15
你得到这个错误是因为registerFailed只接受2个参数,但接缝被3个参数调用。你必须将'registerFailed'改为'void registerFailed(user,error,WAT)'。 – 2013-03-14 07:13:06
@AlexandreArdhuin,这里使用了什么库?我无法找到js.scoped和这个问题中使用的其他方法。 'dart:js'没有他们。 – 2014-02-01 16:42:55