绑定简单是 addeventlistener 的快捷方式
我从来没有真正理解绑定的意义,除了它是 addeventlistener 的有效简写。
还有更多吗?我错过了什么吗?
谢谢, dsdsdsdsd dsdsdsdsd
I never really understood the point of binding, beyond it being effectively shorthand for addeventlistener.
is there more to it? am I missing something?
thanks,
dsdsdsdsd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据绑定就是以声明方式定义数据在 UI 中的显示方式。在幕后,它有点复杂,因为除了挂钩
addEventListener
来支持数据绑定功能之外,还有更多的需求。实际上,这是一个非常强大的功能,为了更多地理解它,我们可以看一个简单的“Hello World”应用程序:
现在,使用
--keep
编译器标志编译此应用程序并查看新文件夹“bin-debug/ generated”。我们对 HelloWorld- generated.as 感兴趣,这里是定义绑定并从构造函数调用的地方:
稍后,在 HelloWorld 构造函数中,您会收到一个设置观察者的调用:
这实际上就是这样做的:
事情变得更多双向绑定很复杂。
Data binding is all about declaratively defining how data is displayed in the UI. Under the hood, it is a bit more complicated, because there are more needs than just hooking
addEventListener
to support the features of data binding.It is a very powerful feature, actually, and to understand it more, we can look at a simple "Hello World" application:
Now, compile this app with the
--keep
compiler flag and look at the new folder "bin-debug/generated". We are interested in HelloWorld-generated.asHere is where that binding gets defined and called from the constructor:
A little later, in the HelloWorld constructor, you get a call to set up the watchers:
Which really just does this:
Things get more complicated with two-way bindings.
Flex 4 中的数据绑定我想可以被描述为 addEventListener() 的快捷方式 - 但这有点像说汽车只是步行的快捷方式。如果您只是绕着街区走一走,没什么大不了的 - 但如果您正在构建一个复杂的应用程序,其中包含大量项目渲染器和大量可能随时变化的数据点,则数据绑定可以让您避免编写数百个 addEventListener () 和removeEventListener() 调用,以及它们关联的处理程序。在这种情况下,这确实是一件大事。
Data Binding in Flex 4 COULD I guess be described as a shortcut for addEventListener() - but that's a bit like saying that cars are just a shortcut for walking. If you're only going around the block, no big deal - but if you're building a complex application with lots of item renderers and lots of data points that can vary at a moment's notice, data binding lets you avoid writing hundreds of addEventListener() and removeEventListener() calls, as well as their associated handlers. It's kind of a really big deal, in that context.