如何将qooxdoo属性绑定到小部件?

时间:2019-11-30 16:13:13

标签: javascript qooxdoo

我对Qooxdoo完全陌生。

我想将属性绑定到标签,如下面的代码所示,但这不起作用:(

qx.Class.define("xxx.view.XxxView",
{
  extend : qx.ui.container.Composite,

  properties : {
    CaseID : {
      check : 'String',
      event : 'changeCaseID',
      init  : '000000000'
    }
  },

  members : {
    _CaseIDLabel : null
  },

  construct : function()
  {
    this._CaseIDLabel = new qx.ui.basic.Label("initial");
    this.CaseID.bind('changeCaseID', this._CaseIDLabel, 'value');
  }
}

thx 4条提示

2 个答案:

答案 0 :(得分:1)

您不能直接访问该属性。您必须使用获取器和设置器来获取其价值。您可以改为绑定整个属性。绑定系统足够聪明,可以检测到发出的事件,提取属性值并将其应用于目标。

这是工作代码

    qx.Class.define("xxx.view.XxxView", {
  extend : qx.ui.container.Composite,

 construct : function() {
   this.base(arguments);
    this._CaseIDLabel = new qx.ui.basic.Label("initial");

    // containers need a layout
    this.setLayout(new qx.ui.layout.Canvas());
    this.add(this._CaseIDLabel);

    // notice here we are binding this object's property
    this.bind('CaseID', this._CaseIDLabel, 'value');
  },

  properties : {
    CaseID : {
      check : 'String',
      event : "changeCaseID",
      init  : '000000000'
    }
  },

  members : {
    _CaseIDLabel : null
  },
});

这是操场上的例子 https://tinyurl.com/rt5v8zx

答案 1 :(得分:1)

这是另一个示例,其处理方式略有不同。请参阅嵌入的注释。

qx.Class.define("xxx.view.XxxView",
{
  extend : qx.ui.container.Composite,

  properties : {
    CaseID : {
      check : 'String',
      event : "changeCaseID",
      init  : '000000000'
    }
  },

  members : {
    _CaseIDLabel : null
  },

  construct : function()
  {
    // We need to call the superclass constructor.
    // In this case, we also provide a layout for this container.
    this.base(arguments, new qx.ui.layout.VBox());

    // Here we instantiate a Label with initial text, but that text
    // will be immediately overwritten so we'll never see it
    this._CaseIDLabel = new qx.ui.basic.Label("initial");
    this.add(this._CaseIDLabel);

    // We can bind to our own property, as done here. Note, though,
    // that this doesn't use the being-initialized value in the property
    // without explicit instruction... so we then force-initialize that
    // property.
    this.bind('changeCaseID', this._CaseIDLabel, 'value');
    this.initCaseID();
  }
});

// Instantiate one of these xxxView objects, and place it on the page
var xxxView = new xxx.view.XxxView();
this.getRoot().add(xxxView, { left : 10, top : 200 } );

// Show how the property value can change later, and update the label
setTimeout(
  function()
  {
    xxxView.setCaseID('Hello world!');    
  },
  2000);

可以在操场上看到它:http://tinyurl.com/vml8bru

相关问题