OpenHarmony开发者论坛
标题:
OpenHarmony 4.0 webview 前端页面调用应用侧函数 返回数组,前端页面调用函数,数据为notSupportType, 文档 复杂类型使用方法 中 Array 的案例
[打印本页]
作者:
feynman
时间:
2024-4-28 14:13
标题:
OpenHarmony 4.0 webview 前端页面调用应用侧函数 返回数组,前端页面调用函数,数据为notSupportType, 文档 复杂类型使用方法 中 Array 的案例
[md]```ts
// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error from '@ohos.base';
class testClass {
constructor() {
}
test(): Array<Number>{
return [1, 2, 3, 4]
}
toString(param:String): void {
console.log('Web Component toString' + param);
}
}
@Entry
@Component
struct Index {
webviewController: web_webview.WebviewController = new web_webview.WebviewController();
@State testObj: testClass = new testClass();
build() {
Column() {
Button('refresh')
.onClick(() => {
try {
this.webviewController.refresh();
} catch (error) {
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Button('Register JavaScript To Window')
.onClick(() => {
try {
this.webviewController.registerJavaScriptProxy(this.testObj, "testObjName", ["test", "toString"]);
} catch (error) {
let e: business_error.BusinessError = error as business_error.BusinessError;
console.error(`ErrorCode: ${e.code}, Message: ${e.message}`);
}
})
Web({ src: $rawfile('index.html'), controller: this.webviewController })
}
}
}
```
```html
<!-- index.html -->
<!DOCTYPE html>
<html>
<body>
<button type="button" onclick="callArkTS()">Click Me!</button>
<p id="demo"></p>
<script>
function callArkTS() {
testObjName.toString(testObjName.test());
}
</script>
</body>
</html>
```
[/md]
作者:
s_hao
时间:
2024-5-9 17:02
说下具体问题是啥,遇到了什么问题,及报错日志
欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/)
Powered by Discuz! X3.5