ในใบสมัครของฉัน ฉันมีรหัสนี้:
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 ปกติ
ตอนนี้ฉันมีการตั้งค่าทั่วโลกว่าค่านั้นควรเริ่มต้นด้วยอะไร วิธีที่ง่ายกว่าในการจัดการกับมันคือการตั้งค่าของช่องทำเครื่องหมาย จากนั้นทริกเกอร์เหตุการณ์:
// 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 });
}
ในขณะที่บรรทัดแรกใช้งานได้ (การตั้งค่าวิดเจ็ต) บรรทัดที่สองไม่ทำงาน -- เหตุการณ์ 'คลิก' จะไม่ถูกทริกเกอร์สำหรับวิดเจ็ตจริงๆ
ฉันลองทุกชุดที่เป็นไปได้ โดยปล่อยเหตุการณ์นี้บน domNode ฯลฯ -- แต่ไม่เลย ดูเหมือนจะไม่ต้องการทำอะไรเลย ใน Button.html ซึ่งเป็นพื้นฐานสำหรับ CheckBox นั้น Dojo มี:
data-dojo-attach-event="ondijitclick:__onClick"
ฉันสงสัยว่านั่นเป็นปัญหาหรือไม่ ดังนั้น... ฉันควรเขียนอะไรสำหรับการจำลองการคลิกช่องทำเครื่องหมาย เต็ม พอยน์เตอร์ใด ๆ ?