#鸿蒙学习大百科#分布式数据对象如何加入组网时不刷新组网中的数据,并且得到组网中的数据?

分布式数据对象如何加入组网时不刷新组网中的数据,并且得到组网中的数据?

HarmonyOS
2024-10-24 10:17:46
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
无敌大暴龙
// 导入模块
import distributedDataObject from '@ohos.data.distributedDataObject';

class People {
  name: string|undefined
  age: number |undefined= 0

  constructor(name: string|undefined, age: number|undefined) {
    this.name = name
    this.age = age
  }
}
@Entry
@Component
struct Index {
  build() {
    Column() {
      Button("创建分布式对象").onClick(() => {
        //将属性设置为undefined。加入组网时不刷新组网中的数据,并且得到组网中的数据
        let people = new People(undefined,undefined)
        let localObject: distributedDataObject.DataObject = distributedDataObject.create(getContext(this), people);
        localObject.setSessionId("123456")//设置sessionId
      })
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
分享
微博
QQ
微信
回复
2024-10-24 17:05:11


相关问题
请问如何实现异地分布式组网
8726浏览 • 1回复 待解决