【发布时间】:2014-08-03 00:58:08
【问题描述】:
在我的应用程序中,我有以下代码:
postCreate: function(){
// ...
// Change the listWidget's order depending on whether the checkbox is
// ticked or not
self.extraWidget.orderByNameWidget.on( 'click', function( e ){
var orderByNameWidget = this;
field = orderByNameWidget.get('value') ? 'firstName' : 'lastName';
// Make up the collection with the initial filters
var collection = self.store;
if( self.initialFilter ) collection = collection.filter( self.initialFilter );
collection = collection.sort( field );
self.listWidget.set('collection', collection);
});
此代码在那里,以便用户可以单击复选框 (orderByNameWidget),并更改联系人的排序。 orderByNameWidget 是一个普通的 Dojo CheckBox。
现在,我有一个全局设置,该值应该从什么开始。更简洁的处理方法是设置复选框的值,然后触发事件:
// Artificially emit the initial click if the default says so
if( ConfigVars.workspacesUsersInfo.orderByNameDefault ){
self.extraWidget.orderByNameWidget.set( 'value', true );
self.extraWidget.orderByNameWidget.emit( 'click', { bubbles: true, cancelable: true });
}
虽然第一行有效(设置小部件),但第二行却没有——实际上从未为小部件触发 'click' 事件。
我尝试了每一种可能的组合,在 domNode 等上发出这个事件——但不,它似乎不想做任何事情。 在 Button.html(CheckBox 的基础)中,Dojo 有:
data-dojo-attach-event="ondijitclick:__onClick"
我想知道这是否是问题所在。那么...我应该为复选框单击的 full 模拟写什么?有什么指点吗?
【问题讨论】:
标签: javascript events dom dojo