繁体   English   中英

在Dojo CheckBox中手动触发点击事件

[英]Trigger click event manually in Dojo CheckBox

在我的应用程序中,我有以下代码:

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等上发出此事件。但是,不,它似乎并不想做任何事情。 在CheckBox的基础Button.html中,Dojo具有:

 data-dojo-attach-event="ondijitclick:__onClick"

我想知道那是不是问题。 所以...对于复选框点击的完整模拟,我应该写些什么? 有指针吗?

是否有原因为什么您不能使用change事件而不是click开始? 应该在用户点击和程序更改上触发。 (和键盘事件,对于这个问题,它click可能不会开火。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM