**上述示例中,父组件ViewB中的类对象ClassB,其包含的对象ClassA与子组件ViewA数据同步时,通过ObjectLink将数据c值的变化状态通知给父组件同步变化。在子组件ViewA中,this.a = new ClassA(0)是不生效的,这里的变量a由@ObjectLink装饰,是不可变的,c值也不会发生改变。**
* **案例2**
```
var nextID: number = 0;
@Observed
class ClassA {
public name: string;
public c: number;
public id: number;
@Entry
@Component
struct Calendar1 {
//模拟12个月
@State calendar: Month[] = [
new Month(2020, 1, [...Array(31).keys()]),
new Month(2020, 2, [...Array(28).keys()]),
new Month(2020, 3, [...Array(31).keys()]),
new Month(2020, 4, [...Array(30).keys()]),
new Month(2020, 5, [...Array(31).keys()]),
new Month(2020, 6, [...Array(30).keys()]),
new Month(2020, 7, [...Array(31).keys()]),
new Month(2020, 8, [...Array(31).keys()]),
new Month(2020, 9, [...Array(30).keys()]),
new Month(2020, 10, [...Array(31).keys()]),
new Month(2020, 11, [...Array(30).keys()]),
new Month(2020, 12, [...Array(31).keys()]),
]
Scroll(this.scroller) {
Column() {
Text("Test Text Visible Change")
.fontSize(20)
.height(200)
.margin({ top: 50, bottom: 20 })
.backgroundColor(Color.Green)
// 通过设置ratios为[0.0, 1.0],实现当组件完全显示或完全消失在屏幕中时触发回调
.onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => {
console.info("Test Text isVisible: " + isVisible + ", currentRatio:" + currentRatio)
if (isVisible && currentRatio >= 1.0) {
console.info("Test Text is fully visible. currentRatio:" + currentRatio)
this.testTextStr = "Test Text is fully visible"
}
if (!isVisible && currentRatio <= 0.0) {
console.info("Test Text is completely invisible.")
this.testTextStr = "Test Text is completely invisible"
}
})
if (!isVisible && currentRatio <= 0.0) {
console.info("Test Row is is completely invisible.")
this.testRowStr = "Test Row is is completely invisible"
}
})