解决方案的关键代码如下:xx.c static napi_value TransObect(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value js_cb; napi_get_cb_info(env, info, &argc, &js_cb, nullptr, nullptr); napi_value str; napi_create_string_utf8(env, “John”, 4, &str); napi_set_named_property(env, js_cb, “sMsg”, str); napi_value staticMethod; napi_get_named_property(env, js_cb, “staticMethod”, &staticMethod); napi_call_function(env, js_cb, staticMethod, 0, nullptr, nullptr); return nullptr; } xx.ets import testNapi from ‘libentry.so’; class tsClass{ static sMsg:string = “Hello”; static staticMethod() { console.log('Static method called. sMsg = ’ + tsClass.sMsg); } } @Entry @Component struct Index { @State message: string = ‘Hello World’; build() { Row() { Column() { Button(‘Test’) .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { testNapi.transobject(tsClass); }) } .width(‘100%’) } .height(‘100%’) } } index.d.ts export const transobject: (a: Object) => void; 本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。
解决方案的关键代码如下:
本文参与了 【 HarmonyOS NEXT 技术问答冲榜,等你来战!】欢迎正在阅读的你也加入。