Javascript 使用onClick事件扩展Aviarc容器小部件
我在屏幕布局中使用了一些容器小部件。我需要扩展容器,使其具有“onClick”事件,以便我可以按照以下方式执行操作:Javascript 使用onClick事件扩展Aviarc容器小部件,javascript,aviarc,Javascript,Aviarc,我在屏幕布局中使用了一些容器小部件。我需要扩展容器,使其具有“onClick”事件,以便我可以按照以下方式执行操作: <screen> <container name="customer-list" ..> <!-- some content over here --> </container> <action:behaviors> <action:when widget-
<screen>
<container name="customer-list" ..>
<!-- some content over here -->
</container>
<action:behaviors>
<action:when widget-event="customer-list.onClick">
<!-- some actions here -->
</action:when>
</action:behaviors>
</screen>
要添加对onClick事件的支持,您需要在小部件中添加以下内容:
WidgetName = function() {
this.onClick = new Toronto.client.Event("WidgetName onClick");
};
在小部件的构造函数中声明事件:
WidgetName = function() {
this.onClick = new Toronto.client.Event("WidgetName onClick");
};
然后在启动方法中添加以下行:
widgetContext.addManagedDOMEvent(this.getContainerElement(), "onclick", this._onClickHandler, this, "WidgetName onClick binding");
剩下唯一要实现的就是实际的处理程序:
, _onClickHandler: function() {
this.onClick.fireEvent({
widget: this
});
}
其思想是向小部件添加事件,将事件绑定到DOM节点,并在处理程序中扩展fireEvent的属性对象,以包含屏幕所需的所有相关细节