UI不能正常显示鸿蒙接口返回数据
2997 浏览 17 点赞 19 收藏
当正常调用鸿蒙接口获取数据时,想用text来显示返回的数据,但是发现返回数据总是不显示
比如说:
js文件中点击click函数获取接口返回的数据
data: {
title: 'World',
moduleGroup: null,
},
click: function() {
this.title = "click";
var type = "get";
if (this.moduleGroup == null) {
this.moduleGroup = ModuleGroup.getGroup("CurDemo/getValue");
}
if (this.moduleGroup != null) {
this.title = "moduleGroup not empty";
this.moduleGroup.callNative(type).then(function(value) {
this.title = value;
});
}
复制
},
发现界面上显示了moduleGroup not empty,但是不显示value的值
这是因为js的闭包问题,解决方法如下:
click: function() {
this.title = "click";
var type = "get";
if (this.moduleGroup == null)
this.moduleGroup = ModuleGroup.getGroup("CurDemo/getValue");
}
if (this.moduleGroup != null) {
this.title = "moduleGroup not empty";
var self = this;
this.moduleGroup.callNative(type).then(function(value) {
self.title = value;
});
}
},©本站发布的所有内容,包括但不限于文字、图片、音频、视频、图表、标志、标识、广告、商标、商号、域名、软件、程序等,除特别标明外,均来源于网络或用户投稿,版权归原作者或原出处所有。我们致力于保护原作者版权,若涉及版权问题,请及时联系我们进行处理。
分类
其它
标签
UI
鸿蒙接口
相关推荐
深圳启用全国首个鸿蒙智慧地铁站
7912
0鸿蒙版千问重磅更新,开启瓜分30亿春节活动
三元桥的水冰兔
7289
0同样使用@State装饰器,有时第三层数据可以更新UI,有时不可以,是什么原因?
鸿蒙小助手
5331
0使用 @Builder数据刷新后UI没有刷新,导致图片错乱怎么解决?
鸿蒙小助手
7381
0宋你一朵小红花
我还没有写个人简介......
881
帖子
0
提问
1679
粉丝
最新发布
华为鸿蒙 HarmonyOS 6.0.0.108 SP2 Developer 版本新增 9 套桌面图标
2025-10-20 23:17:16 发布注意!华为开启鸿蒙6.0系统推送,稳定性提升
2025-10-14 15:10:36 发布热门推荐