xdd666t / ohos_smart_dialog

吊打鸿蒙原生弹窗
MIT License
62 stars 8 forks source link

如何更新正在展示的弹框?嵌套层数有三层,使用@ObservedV2没有效果 #20

Closed d495988379 closed 2 hours ago

d495988379 commented 2 hours ago

实体类

@ObservedV2
export class SiftBeanDataAreaListList {
    title?: string = "";
    content?: number = 0;
    type?: number = 0;
    param1?: string = "";
    @Trace isSelect?: boolean = false;
}

@ObservedV2
export class SiftBeanDataAreaList {
    title?: string = "";
    @Trace list?: SiftBeanDataAreaListList[] = [];
}

@ObservedV2
export class SiftBeanDataArea {
    topTitle?: string = "";
    @Trace list?: SiftBeanDataAreaList[] = [];
}

@ObservedV2
export class SiftBeanData {
    @Trace area?: SiftBeanDataArea = new SiftBeanDataArea();
}`

数据获取
`@ComponentV2
export struct HouseListPage {
 model: SiftBeanData = new SiftBeanData()
aboutToAppear(): void {

    let parms: HouseListParms = {
      cityId: this.currentCityId,
      searchType: 2
    };

    let data = new HouseListModel().getSiftList(parms);
    data.then((res: SiftBeanData) => {
      this.model = res
    }).catch((err: object) => {
      ToastUtil.showToast(json.stringify(err))
    })
  }
}`
弹框
`SmartDialog.showAttach({
                  targetId: "region",
                  builder: customLoading,
                  builderArgs: this.model.area?.list!![0].list,
                  alignment: Alignment.Bottom,
                  maskBuilder: dialogCustomMask,
                  clickMaskDismiss: true,
                })

@Builder
function customLoading(model: SiftBeanDataAreaListList[]) {
  AreaItemLayout({ model: model })
}

@ComponentV2
struct AreaItemLayout {
  @Require @Param model?: SiftBeanDataAreaListList[]
  build() {
    Column() {
      List() {
        ForEach(this.model, (item: SiftBeanDataAreaListList, index: number) => {
          ListItem() {
            Text(item.title)
              .fontColor(item.isSelect ? $r('app.color.color_ff2A6EEB') : $r('app.color.color_ff323233'))
              .padding({ top: 10, bottom: 10 })
              .onClick(() => {
                item.isSelect = !item.isSelect;
              })
          }
        }, (item: SiftBeanDataAreaListList, index: number) => json.stringify(item))
      }
      .scrollBar(BarState.Off)
      .width('100%')
    }
    .alignItems(HorizontalAlign.Start)
    .backgroundColor(Color.White)
    .width('100%')
  }
}

以上是弹框的主要代码,目前点击item想改变选中状态 但是没有刷新效果

xdd666t commented 2 hours ago

SmartDialog支持UI数据刷新, 可以参考: https://github.com/xdd666t/ohos_smart_dialog/issues/10

你上面的明显是业务逻辑问题, 接口请求回来的数据是字面对象,非V2, 自己查查吧

还有, 给不出完整可运行的简化demo的issue, 大概率会被直接关掉

d495988379 commented 2 hours ago

SmartDialog支持UI数据刷新, 可以参考: #10

你上面的明显是业务逻辑问题, 接口请求回来的数据是字面对象,非V2, 自己查查吧

还有, 给不出完整可运行的简化demo的issue, 大概率会被直接关掉

你好 非V2是什么意思? 接口目前就是返回一个对象 里面是数组嵌套 我按照#10写了一下 并不能更新 求大佬指导下