简体   繁体   English

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

[英]Trigger click event manually in Dojo CheckBox

In my application, I have this code: 在我的应用程序中,我有以下代码:

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);

  });

This code is there so that the user can click on a checkbox (orderByNameWidget), and change the sorting of contacts. 有了此代码,用户可以单击复选框(orderByNameWidget),并更改联系人的排序。 orderByNameWidget is a normal Dojo CheckBox. orderByNameWidget是一个普通的Dojo CheckBox。

Now, I have a global setting of what that value should be to start with. 现在,我已经开始设定该值的全局设置。 The neater way to deal with it would be setting the value of the checkbox, and then trigger the event: 处理它的更整洁的方法是设置复选框的值,然后触发事件:

  // 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 });
  }

While the first line works (setting the widget), the second one doesn't -- the 'click' event is never actually triggered for the widget. 尽管第一行有效(设置窗口小部件),但第二行却不起作用-窗口小部件实际上不会触发'click'事件。

I tried every single possible combination, emitting this event on the domNode etc. -- but no, it doesn't seem to want to do anything. 我尝试了每种可能的组合,并在domNode等上发出此事件。但是,不,它似乎并不想做任何事情。 In Button.html, the basis for CheckBox, Dojo has: 在CheckBox的基础Button.html中,Dojo具有:

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

I wonder if that's the problem. 我想知道那是不是问题。 So... what should I write for a full simulation of the checkbox click? 所以...对于复选框点击的完整模拟,我应该写些什么? Any pointers? 有指针吗?

Is there a reason why you can't use the change event instead of click to begin with? 是否有原因为什么您不能使用change事件而不是click开始? That ought to fire on both user clicks and programmatic changes. 应该在用户点击和程序更改上触发。 (And keyboard events, for that matter, which click likely won't fire on.) (和键盘事件,对于这个问题,它click可能不会开火。)

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

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