什么是冒泡概念? [英] What is the bubbling concept?

查看:145
本文介绍了什么是冒泡概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过事件和答案冒泡起来,但是与泡沫有什么关系?

I've heard of events and SO answers "bubbling up", but what has all that got to do with bubbles?

推荐答案

事件冒泡是通过深层结构向上移动的信息,正确的设计要求通常信息只能向下流动。

Event bubbling is the idea of information moving up through a deep structure, when proper design dictates that normally information should only flow downward.

以非常基本的术语,思考的单个对象。正确设计,这个对象应该只知道自己的子对象。它应该与其父母没有直接的互动。反过来,它的孩子和父母也应遵循同样的规则。实际上,这意味着信息只能向下流动 - 父母可以调用一种方法,将数据发送到其孩子的数据或从其孩子中提取数据,但是孩子不能强制对其父母执行相同操作。

In very basic terms, think of a single object. Properly designed, this object should only know about its own child objects. It should have no direct interaction with its parent. Its children and parent objects, in turn, should follow the same rules. In effect, this means that information can only flow downward - a parent can invoke a method, send data into or extract data from its child, but the child cannot forcibly do the same to its parent.

想想当你在水下吹泡泡时会发生什么 - 你不必将空气推向表面 - 你只需释放它,它就会自动移动。相同的概念适用于事件冒泡 - 更深层次的控件简单地释放他们的信息 - 通常通过一个事件 - 它浮动链,而不直接调用任何东西。

Think of what happens when you blow an air bubble underwater - you don't have to push the air towards the surface - you simply release it and it moves on its own. The same concept applies to event bubbling - deeper controls simply "release" their information - usually via an event - and it "floats" up the chain without directly invoking anything.

关于像Stackoverflow(或几乎任何一种网站)这样的网站,冒泡的概念是一样的。显然,每个单独的帖子都不应该直接放在主页上,而是当一个单一的帖子被更新时,这个事件从层次结构中的最深点发布 - 一个单独的帖子,并且最终到达顶层处理(选择是否在主页上显示)。

With regard to a website like Stackoverflow (or practically any kind of site), the concept of bubbling is the same. Obviously each individual post ought not directly put itself on the home page, but when a single post has been updated, that event is released from the deepest point in the hierarchy - a single post - and floats up to eventually the top level, where it is dealt with (choosing whether or not to display on the home page).

这篇关于什么是冒泡概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆