New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jscore中类的使用问题 #1
Comments
经过尝试代码改成这样就可以恢复正常 class TestBug extends StatelessWidget {
static JSClassDefinition classDef = JSClassDefinition(
version: 0,
attributes: JSClassAttributes.kJSClassAttributeNone,
className: 'Text',
initialize: Pointer.fromFunction(jsClassInitialize),
callAsConstructor: Pointer.fromFunction(jsClassConstructor),
staticFunctions: [],
);
static JSClass jsClass = JSClass.create(classDef);
static Pointer jsClassConstructor(
Pointer ctx,
Pointer constructor,
int argumentCount,
Pointer<Pointer> arguments,
Pointer<Pointer> exception) {
String text;
final context = JSContext(ctx);
final that = JSObject.make(context, jsClass);
if (argumentCount >= 1) {
final arg1 = JSValue(context, arguments[0]);
if (arg1.isString) {
text = arg1.string;
}
}
that.setProperty('text', JSValue.makeString(context, text),
JSPropertyAttributes.kJSPropertyAttributeDontDelete);
return that.pointer;
}
static void jsClassInitialize(Pointer ctx, Pointer object) {
print('jsClassInitialize');
// final context = JSContext(ctx);
// final obj = JSObject(context, object);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
child: Text('TEST'),
onPressed: () {
final jsContext = JSContext.createInGroup();
var flutterJSObject = JSObject.make(jsContext, jsClass);
jsContext.globalObject.setProperty('Text', flutterJSObject.toValue(),
JSPropertyAttributes.kJSPropertyAttributeDontDelete);
final data = jsContext.evaluate("""
[new Text('测试1'), new Text('测试2'), new Text('测试3')]
""");
final list = jsValueToList(data)
.map((e) => e.toObject().getProperty('text').string);
print(list);
},
)),
);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我在dart里创建的类,js里初始化后返回到dart再取值发现取到的都是最后一个
js执行的:
[new Text('测试1'), new Text('测试2'), new Text('测试3')]
;到dart中取到的内容是
(测试3, 测试3, 测试3)
全部变成最后一个了
大佬帮忙看看是不是用的方法不对.
完整代码如下:
The text was updated successfully, but these errors were encountered: