1.When use which
The short answer is: Usedelegate
except when you cannot usedelegate
.
哈哈哈哈写文档的真的太可爱了。
Event delegation is a technique used to improve application performance. It drastically reduces the number of event subscriptions by leveraging the "bubbling" characteristic of most DOM events. With event delegation, handlers are not attached to individual elements. Instead, a single event handler is attached to a top-level node such as the body element. When an event bubbles up to this shared top-level handler the event delegation logic calls the appropriate handler based on the event's target .
意思是用delegate是为了减少事件订阅,一个event handler会被attach to一个顶级的node比如说body。当时间冒泡到顶级的handler时候会根据event的target来调用合适的handler。
Once you're on the event's MDN page, check whether the eventbubbles
. Only events that bubble can be used with Aurelia'sdelegate
binding command. Theblur
,focus
,load
andunload
events do not bubble so you'll need to use thetrigger
binding command to subscribe to these events.
只有可以冒泡的事件才能使用Aurelia的绑定delegate。blur,focus,load,unload并不能事件冒泡所以不能用delegate只能用trigger。
Use
trigger
on buttons when the following conditions are met:This will ensure clicks on disabled button's children won't bubble up to the delegate event handler.
- You need to disable the button.
- The button's content is made up of other elements (as opposed to just text).
注意: 下面两种情况请在button上使用trigger1.想要disable这个button2.这个button的内容是由其他内容组成,而不仅仅只是text。这会保证disabled button children上的点击不会冒泡到delegate event handler。