前端框架Aurelia - Delegate vs Trigger
2017-03-23 20:05
375 查看
1.When use which
The short answer is: Usedelegateexcept
when you cannot use
delegate.
哈哈哈哈写文档的真的太可爱了。
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 event
bubbles.
Only events that bubble can be used with Aurelia's
delegatebinding
command. The
blur,
focus,
loadand
unloadevents
do not bubble so you'll need to use the
triggerbinding command to subscribe to these events.
只有可以冒泡的事件才能使用Aurelia的绑定delegate。
blur,focus,load,unload并不能事件冒泡所以不能用delegate只能用trigger。
Use trigger
on buttons when the following conditions are met:
You need to disable the button.The button's content is made up of other elements (as opposed to just text).
This will ensure clicks on disabled button's children won't bubble up to
the delegate event handler.
注意:
下面两种情况请在button上使用trigger
1.想要disable这个button
2.这个button的内容是由其他内容组成,而不仅仅只是text。
这会保证disabled
button children上的点击不会冒泡到delegate event handler。
相关文章推荐
- 前端框架Aurelia —— 路由Router
- 前端开发框架三剑客—AngularJS VS. Backone.js VS.Ember.js
- angularjs(二):前端开发框架三剑客—AngularJS VS. Backone.js VS.Ember.js
- 前端框架Aurelia——组件Component(二)组件生命周期
- WEB前端开发框架Bootstrap3 VS Foundation5
- 前端框架Aurelia - feature()
- 选择前端框架:Angular VS React
- 如何选择前端框架:ANGULAR VS EMBER VS REACT
- 如何选择前端框架:ANGULAR VS EMBER VS REACT
- 前端框架Aurelia - 数据绑定bind(一)
- 前端框架Aurelia - Binding Checkbox
- 前端框架Aurelia - Binding Selects(一)
- 前端框架大比拼:Angularjs vs Reactjs vs Vue.js
- 前端框架Aurelia - Computed Properties
- 如何选择前端框架:ANGULAR VS EMBER VS REACT
- 前端框架Aurelia——组件Component(一)
- 如何选择前端框架:ANGULAR VS EMBER VS REACT
- 前端框架Aurelia - 自定义组件
- 【JavaScript】前端开发框架三剑客—AngularJS VS. Backone.js VS.Ember.js
- 前端框架Aurelia - Value Converter