HarmonyOS Swiper能接口请求完成后更新数据吗,给个具体demo吗?

Swiper能接口请求完成后更新数据吗?

HarmonyOS
2024-10-12 09:54:27
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

请使用list结合LazyForEach实现需求,当LazyForEach数据源发生变化,需要再次渲染时,根据数据源的变化情况调用listener对应的接口,通知LazyForEach做相应的更新。demo参考:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/arkts-rendering-control-lazyforeach.md#%E9%9D%9E%E9%A6%96%E6%AC%A1%E6%B8%B2%E6%9F%93

class BasicDataSource implements IDataSource {  
  private listeners: DataChangeListener[] = [];  
  private originDataArray: string[] = [];  
  public totalCount(): number {  
    return 0;  
  }  
  public getData(index: number): string {  
    return this.originDataArray[index];  
  }  
  registerDataChangeListener(listener: DataChangeListener): void {  
    if (this.listeners.indexOf(listener) < 0) {  
      console.info('add listener');  
      this.listeners.push(listener);  
    }  
  }  
  unregisterDataChangeListener(listener: DataChangeListener): void {  
    const pos = this.listeners.indexOf(listener);  
    if (pos >= 0) {  
      console.info('remove listener');  
      this.listeners.splice(pos, 1);  
    }  
  }  
  notifyDataReload(): void {  
    this.listeners.forEach(listener => {  
      listener.onDataReloaded();  
    })  
  }  
  notifyDataAdd(index: number): void {  
    this.listeners.forEach(listener => {  
      listener.onDataAdd(index);  
      // 写法2:listener.onDatasetChange([{type: DataOperationType.ADD, index: index}]);  
    })  
  }  
  notifyDataChange(index: number): void {  
    this.listeners.forEach(listener => {  
      listener.onDataChange(index);  
    })  
  }  
  notifyDataDelete(index: number): void {  
    this.listeners.forEach(listener => {  
      listener.onDataDelete(index);  
    })  
  }  
  notifyDataMove(from: number, to: number): void {  
    this.listeners.forEach(listener => {  
      listener.onDataMove(from, to);  
    })  
  }  
}  
class MyDataSource extends BasicDataSource {  
  private dataArray: string[] = [];  
  
  public totalCount(): number {  
    return this.dataArray.length;  
  }  
  public getData(index: number): string {  
    return this.dataArray[index];  
  }  
  public addData(index: number, data: string): void {  
    this.dataArray.splice(index, 0, data);  
    this.notifyDataAdd(index);  
  }  
  public pushData(data: string): void {  
    this.dataArray.push(data);  
    this.notifyDataAdd(this.dataArray.length - 1);  
  }  
}
分享
微博
QQ
微信
回复
2024-10-12 17:05:58
相关问题
HarmonyOS 接口请求处理
265浏览 • 1回复 待解决
HarmonyOS 接口请求处理处理
97浏览 • 1回复 待解决
鸿蒙JS开发 接口请求loading??
6383浏览 • 1回复 已解决
鸿蒙JS开发 接口请求loading?
5567浏览 • 1回复 待解决
鸿蒙JS开发 蓠接口请求loading?
3744浏览 • 1回复 待解决
系统VPN播打完成后是否可以打通资源
1890浏览 • 1回复 待解决
HarmonyOS Swiper支持动态修改数据
511浏览 • 1回复 待解决
HarmonyOS Refresh支持swiper
33浏览 • 1回复 待解决
HarmonyOS应用更新demo
324浏览 • 1回复 待解决