Dialog封裝報錯Error name:TypeError Error message:is not callable

報錯

Error name:TypeError Error message:is not callable Stacktrace: at PUV2ViewBase (/usr1/hmos_for_system/src/increment/sourcecode/foundation/arkui/ace_engine/frameworks/bridge/declarative_frontend/engine/stateMgmt.js:4029:1) at ViewPU (/usr1/hmos_for_system/src/increment/sourcecode/foundation/arkui/ace_engine/frameworks/bridge/declarative_frontend/engine/stateMgmt.js:6213:1) at WheelPickerDialog (entry/src/main/ets/common/widgets/dialog/WheelPickerDialog.ets:8:1) at showUniversalDialog (entry/src/main/ets/common/utils/WheelPickerUtils.ets:13:20) at showSocPicker (entry/src/main/ets/common/utils/WheelPickerUtils.ets:107:22) at showSocPicker (entry/src/main/ets/pages/car/OutDisChargeElePage.ets:564:22) at anonymous (entry/src/main/ets/pages/car/OutDisChargeElePage.ets:242:18) at anonymous (entry/src/main/ets/pages/car/OutDisChargeElePage.ets:367:9)

/**
   * 顯示通用選擇器
   * @param options 配置選項
   */
  static showUniversalDialog(options: WheelPickerOptions) {
    const dialog = new WheelPickerDialog({
      title: options.title || '選擇',
      positiveText: options.positiveText || '確認',
      negativeText: options.negativeText || '取消',
      showPositive: options.showPositive ?? true,
      showNegative: options.showNegative ?? true,
      pickerConfigs: options.columns,
      onConfirmCallback: (...values: string[]) => {
        if (options.onConfirm) {
          options.onConfirm(...values)
        }
      },
      onCancelCallback: () => {
        if (options.onCancel) {
          options.onCancel()
        }
      }
    })

    const controller = new CustomDialogController({
      builder: dialog,
      autoCancel: true,
      alignment: DialogAlignment.Bottom,
      offset: { dx: 0, dy: 0 },
      customStyle: true,
      gridCount: 4
    })

    dialog.controller = controller
    controller.open()
  }

一調(diào)用這個方法就崩潰,這個問題的根本原因是不能在工具類中彈dialog導致的,代碼放到page頁面中就沒問題了,在 Page 中創(chuàng)建 Controller:CustomDialogController 必須在 Page 組件中創(chuàng)建和打開

另外目前測試頁面的彈窗不能這樣單獨創(chuàng)建dialog:

image.png

必須要放到方法builder里面創(chuàng)建:

image.png

否則就會崩潰。

image.png

工具類中這樣寫彈窗也彈不出來,所以彈窗不要封裝工具類,直接在頁面創(chuàng)建,這兩天算是好好踩踩坑,摸索一下。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容