HarmonyOS jscrash,代码报Error message:is not callable
@Entry()
@ComponentV2
struct Index {
  vm = new ViewModel()
  build() {
    Column() {
      Row() {
        ForEach(this.vm.names, (item: string, index: number) => {
          Column() {
            PersonComponent({
              name: item,
              color: index == this.vm.currentIndex ? Color.Red : Color.Blue
            })
            // 下面这个版本不崩溃
            // if (this.vm.currentIndex == index) {
            //   PersonComponent({
            //     name: item,
            //     color: Color.Red
            //   })
            // } else {
            //   PersonComponent({
            //     name: item,
            //     color: Color.Blue
            //   })
            // }
          }.onClick(() => {
            this.vm.currentIndex = index
          })
        })
      }.alignItems(VerticalAlign.Center).height('100%')
    }.alignItems(HorizontalAlign.Center).width('100%')
  }
}
@ComponentV2
struct PersonComponent {
  name: string = ''
  color: ResourceColor = Color.Blue
  build() {
    Column() {
      Shape() {
        Circle().width(50).height(50).fill(this.color).strokeOpacity(0)
      }.width(50).height(50)
      Text(this.name)
    }
  }
}
@ObservedV2
class ViewModel {
  @Trace names = ['Alice', 'Bob', 'Charles', 'David', 'Eve']
  @Trace currentIndex = 0
}
        HarmonyOS
      
        赞
        
 收藏 0
 回答 1
 
        待解决
        
相关问题
 HarmonyOS  上传失败报Error: empty error message 
1063浏览  • 1回复 待解决
使用BuilderParam在父组件调用this的方法报错:Error message:is not callable 
3087浏览  • 1回复 待解决
HarmonyOS 页面跳转传递的参数,在回调中访问报错:Error message:is not callable 
1619浏览  • 1回复 待解决
HarmonyOS 多次调用createAudioCapturer报 failed, code is 6800301, message is system error 
1810浏览  • 1回复 待解决
在native里面写一个获取以太网MAC地址的接口,但是报错了Error message: is not callable 
4064浏览  • 1回复 待解决
冷启动报错Error message 
3461浏览  • 1回复 待解决
app启动crash报错Error message:MainPage: 
3010浏览  • 1回复 待解决
HarmonyOS  request.uploadFile 报错 empty error message 
1620浏览  • 1回复 待解决
HarmonyOS napi_create_buffer_copy调用返回error status 1 error message: Invalid parameter 
1098浏览  • 1回复 待解决
worker postmessagejs异常 Error message:transfer list must be an Array 
3129浏览  • 1回复 待解决
HarmonyOS 在onWindowStageCreate调用requestEnableNotification报错 {"code":1600001} message is Internal error 
1324浏览  • 1回复 待解决
HarmonyOS 系统路由表导航error code = 100005, error.message = Builder function not registered.., 
1169浏览  • 1回复 待解决
TextDetectorType IDE飘红;运行时相关接口崩溃Error message:Method not implemented 
2495浏览  • 1回复 待解决
HarmonyOS 使用audio.createAudioCapturer开发音频录制功能,调用audioCapturer.stop的时候报错 error:{ code: 600301, message.....: "system error" } 
1408浏览  • 1回复 待解决
HarmonyOS 配置自动签名,但打包时还是报code:9568320 error: no signature file 
1988浏览  • 1回复 待解决
ide执行编译hap时,经常报ERROR: missing:错误是怎么回事? 
633浏览  • 0回复 待解决
HarmonyOS c++代码调用popen,提示popen error:Permission denied 
974浏览  • 1回复 待解决
HarmonyOS 图片资源通过getStringByNameSync获取时的jscrash问题 
1110浏览  • 1回复 待解决
HarmonyOS geoLocationManager.getAddressesFromLocation将坐标转换为地理描述报错“{code":3301300,"message":"BussinessError 
1052浏览  • 1回复 待解决
升级RN到4.1.0.300版本之后运行报错Error message:Cannot read property isDebugModeEnabled of undefined 
2331浏览  • 1回复 待解决
通过datashare访问数据库时,报HksDecrypt failed with error -3是什么原因? 
2676浏览  • 1回复 待解决





















@Track是class对象的属性装饰器。当一个class对象是状态变量时,@Track装饰的属性发生变化,只会触发该属性关联的UI更新;而未被标记的属性不能在UI中使用。
代码示例中的color、name未被@Track修饰,无法导致UI刷新,故会导致jscrash。
正确用法,类似于在ForEach的Column中直接刷新UI,例如Text(“索引” + this.vm.currentIndex)
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-track-V5