exml 的 单个对象的数据绑定 教程

1:先定义  皮肤(skin.CommonCountDownSkin)对应的类 CommonCountDownSkin. 实现皮肤需要绑定的值 如:labelColor
export class CommonCountDownSkin extends eui.Component {

  // 倒计时字体的颜色
  private _label_color: number = 0x000000;
  public get labelColor(): number {
    return this._label_color;
  }
  public set labelColor(value: number) {
    this._label_color = value;
  }

}

 

2:  在xml里面使用如: CommonCountDownSkin.exml

<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="skin.CommonCountDownSkin" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing">
<e:Label />
</e:Skin>

 

3:关键点: 在其它EXML使用这个自定义的组件

<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="skin.GiftsPanel" xmlns:e="http://ns.egret.com/eui" xmlns:ViewCommonComponet="ViewCommonComponet.*"
xmlns:ns1="*" xmlns:w="http://ns.egret.com/wing" xmlns:ViewHome="ViewHome.*" width="750" height="1334">

  <ViewCommonComponet:CommonCountDownSkin />

</e:Group>
</e:Skin>

 

这样就能达到EXML动态数据的绑定。减少属性设置

 

本质就是给ViewCommonComponet类labelColor 设置一个值。  这样做的唯一好处是 egret swing 组件 在使用这个属性的时候 能动态及时体现出来!!!! 

 

 

使用方案:

将类中某个变量赋值给组件的属性,就能实现数据绑定了。如source=“{imgurl}”,imgurl为类中某个变量

相关文章:

  • 2021-12-01
  • 2022-02-06
  • 2021-12-24
  • 2022-12-23
  • 2021-06-04
  • 2021-06-02
  • 2021-12-04
猜你喜欢
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2021-06-13
相关资源
相似解决方案