Implementing a Widget Property"

From Documentation
m (Created page with '{{ZKComponentDevelopmentEssentialsPageHeader}} A property usually has a getter and a setter. The getter is straightforward: <source lang=javascript"> _value: '', //default valu…')
 
m
Line 3: Line 3:
 
A property usually has a getter and a setter. The getter is straightforward:
 
A property usually has a getter and a setter. The getter is straightforward:
  
<source lang=javascript">
+
<source lang="javascript">
 
_value: '', //default value
 
_value: '', //default value
 
   
 
   
Line 14: Line 14:
 
How we update depends on the DOM content. In this example, we use HTML's span to enclose the value, so we only need to change innerHTML.
 
How we update depends on the DOM content. In this example, we use HTML's span to enclose the value, so we only need to change innerHTML.
  
<source lang=javascript">
+
<source lang="javascript">
 
setValue: function(value) {
 
setValue: function(value) {
 
  if (this._value != value) {
 
  if (this._value != value) {

Revision as of 02:06, 14 July 2010


A property usually has a getter and a setter. The getter is straightforward:

_value: '', //default value
 
getValue: function () {
 return this._value;
}

The setter is defined in a similar manner except we have to modify the DOM tree if it has been attached. A widget inherits a property called node which is assigned a reference to a DOM element if the widget has been attached to the DOM tree. If a widget is attached to DOM, this.desktop will be a reference to the desktop (zk.Desktop) it belongs. Otherwise, it is null. How we update depends on the DOM content. In this example, we use HTML's span to enclose the value, so we only need to change innerHTML.

setValue: function(value) {
 if (this._value != value) {
  this._value = value;
  if (this.desktop) this.$n().innerHTML = zUtl.encodeXML(value);
 }
}



Last Update : 2010/07/14

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.