简体   繁体   English

在 Seaside 中获取父组件

[英]Get parent component in Seaside

I wanted to see if there is any possibility in Seaside that a child component gets the reference to the parent component, without using the session or parameter passage.我想看看 Seaside 中是否有任何可能性,即子组件获取对父组件的引用,而不使用 session 或参数通道。 That is, the child component making, for example, a call to self gets the parent component.也就是说,子组件,例如,调用 self 获取父组件。

The short answer is that there is no simple way to do that.简短的回答是,没有简单的方法可以做到这一点。

The reason is that subclasses of WAComponent (and also WAPresenter ) have no direct reference to a parent component, since for rendering purposes this is not needed, because the visitor performs a top-down path and depending on a parent element introduces a coupling of some sort, and an instance variable that might not be used.原因是WAComponent (以及WAPresenter )的子类没有直接引用父组件,因为出于渲染目的,这不是必需的,因为访问者执行自上而下的路径并且依赖于父元素引入了一些耦合排序,以及一个可能不会被使用的实例变量。

To overcome that, I have my own WAComponent subclass, let's call it EAMComponent and this component has a parent instance variable (and in my case, also a model instance variable).为了克服这个问题,我有自己的WAComponent子类,我们称它为EAMComponent ,这个组件有一个parent实例变量(在我的例子中,还有一个model实例变量)。

The EAMComponent class implements on: modelObject in: parentComponent (as well as on: and in: that depend on the former, influenced by Dolphin's implementation of Model-View-Presenter ). EAMComponent class实现on: modelObject in: parentComponent (以及on:in:依赖于前者,受Dolphin 的 Model-View-Presenter 实现的影响)。

So then on the parent component the resulting idiom is something like:因此,在父组件上,生成的习语类似于:

createChildrenComponents

  dateComponent := EAMTextComponent on: self date in: self.
  footerComponent := EAMFooterComponent in: self.

Then in the footer component you can easily refer to the parent that is the object passed as argument to the in: part of the selector.然后在页脚组件中,您可以轻松地引用作为参数传递给选择器的in:部分的 object 的parent级。

Iirc, the absence of a reference to a Component's parent was a conscious design decision. Iirc,没有引用组件的父级是一个有意识的设计决定。 It is important for keeping components decoupled and self-contained.保持组件解耦和独立是很重要的。 This is not to say that esteban's suggestion is wrong, we've also implemented something similar.这并不是说 esteban 的建议是错误的,我们也实现了类似的东西。 You can do it, but it may have consequences like lingering references and hurdles to the reusability of components.您可以这样做,但它可能会产生诸如挥之不去的引用和组件可重用性障碍之类的后果。

The normal way of dealing with this in Seaside is to connect the component loosely to its parent using announcements.在 Seaside 中处理此问题的正常方法是使用公告将组件松散地连接到其父级。 The parent wires up its children to send it back an announcement.父级连接其子级以向其发送通知。

See: this example见: 这个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM