API
Class

ViewComponent ($UI/system/lib/base/viewComponent)

使用范围:UI2

Contents

class ViewComponent ($UI/system/lib/base/viewComponent) extends Component

可视组件基类

Constructor Top

  ViewComponent ()
  ViewComponent ( options)

Static Properties & Enumerations Top

DATA_CHANGED = "onDataChanged"

组件关联的数据项值变化事件

Properties Top

$domNode

组件关联的dom节点的jquery对象

domNode

组件关联的dom节点

Methods Top

void addClass (String cls)
String buildTemplate ( config)
Boolean controlsDescendantBindings ()
void dispose ()
ViewComponent getComponentByCompID ()
getElementByCompID ()
init ( value, bindingContext)
void inited ()
void processComponentAttr ( element, attrs)
void removeClass (String cls)
void setCSS (String css)
void toggleClass (String cls)
void update ( value, bindingContext)

Constructor details Top

public ViewComponent ()

可视组件基类

public ViewComponent ( options)

构造函数

	
		参数options格式类似{parent:xx, config:{}},parent是组件的父节点,允许为空或不指定,config是组件的参数选项
	 

Parameters

options

参数选项

Static Properties & Enumerations Detail Top

static public DATA_CHANGED = "onDataChanged"

组件关联的数据项值变化事件

	
	事件对象的内容如下:
{
    name: name, //数据项名称
    value: value, //数据项新值
    oldValue: oldValue, //数据项旧值
    allValue: allValue, //所有数据项新值
    allOldValue: allOldValue, //所有数据项旧值
    source: this //组件自身
}
	

Properties Detail Top

public $domNode

组件关联的dom节点的jquery对象

public domNode

组件关联的dom节点

Methods Detail Top

public void addClass (String cls)

组件节点上添加css class

Parameters

String cls

Return Value

void

public String buildTemplate ( config)

生成组件模板

	
	参数config来自于new组件时参数{parent:xx, config:{}}中的config的值。
	buildTemplate只有在js动态创建时才被调用,在W文件中声明使用组件时,组件模板通过服务端java解析;
支持js动态创建的组件必须重载buildTemplate方法。
	

Parameters

config

组件选项

Return Value

String

字符串格式的组件模板

public Boolean controlsDescendantBindings ()

组件是否自己控制子节点的数据绑定

	如果组件自己控制子节点的数据绑定,界面引擎将不会遍历组件的子节点,需要
由组件自己处理。 

Return Value

Boolean

public void dispose ()

析构函数

Return Value

void

public ViewComponent getComponentByCompID ()

在当前组件的子节点中,根据compId查找组件

Return Value

ViewComponent

组件实例

public getElementByCompID ()

在当前组件的子节点中,根据compId查找节点

Return Value

element

public init ( value, bindingContext)

初始化组件

	
	 如果返回{ dependence:true}时,表示组件还没有初始化完成,它依赖其它组件,在要获取其其它组件
的promise的回调中调用当前组件的inited方法,通知界面引擎组件初始化完成。
	

Parameters

value

组件关联的数据项的值

bindingContext

数据上下文

Return Value

obj 返回值类似\{dependence: true/false\},其中dependence表示组件是否异步依赖别的组件

public void inited ()

组件初始化完成

	inited方法是给组件开发者使用的,用来标记组件已经初始化完成。大部分情况下组件开发者不需要调用这个
方法,只有当组件的init中需要依赖其它组件时,才需要在异步的回调中调用组件自身的inited标记当前组件已经
初始化完成。代码类似:
        init: function(value, bindingContext){
	        this.callParent(value, bindingContext);
           	var self = this;
           	this.getModel().componentPromise("otherComponentXid").done(function(otherComponent){
            		self.inited();
            	}).fail(function(err){
            		alert(err);
           	});
           	return {dependence: true};
        }

Return Value

void

public void processComponentAttr ( element, attrs)

处理组件关联的数据项

Parameters

element

绑定组件的节点

attrs

需要生成数据项的属性,是一个json数据,其中key是节点的属性名称,value是生成的数据项名称

Return Value

void

public void removeClass (String cls)

组件节点上删除css class

Parameters

String cls

Return Value

void

public void setCSS (String css)

设置组件节点的样式

Parameters

String css

Return Value

void

public void toggleClass (String cls)

添加或删除组件节点上css class

Parameters

String cls

Return Value

void

public void update ( value, bindingContext)

更新组件

	当组件关联的数据项的值发生改变时,会调用组件实例的update方法。 

Parameters

value

组件关联的数据项的值

bindingContext

数据上下文

Return Value

void