質問

I'm trying to set the instance variable of a child component from it's parent component inside a callback. Using the debugger I can see that the instance variable is set correctly in the callback, but on rendering the child component, the child component does not reflect the changes made.

So, is it illegal to modify a component's state from another component in seaside or am I doing something else wrong?

Example code:

MyParentComponent>> initialize
    super initialize.
    child := MyChildComponent new.

MyParentComponent>> renderContentOn: html 
  html render: child.   
  html anchor
     callback: [ 
        child property: 'Something'.
    ] ; with 'Navigate'.

MyParentComponent>> children 
  ^ Array with: child
役に立ちましたか?

解決 2

After a little experimenting, I found the problem. In one of the rendering methods, I was creating a new component each time the page was rendered instead of reusing the one created in the initialize method.

That other component was used for navigation, where I set which main component was to be displayed based on the menu chosen.

So apparently, modifying state is not illegal in Seaside.

他のヒント

You miss some super initialize in the parent component I guess.

I also suggest you don't work this way.

Do a MyParentComponent>>child with

  ^ child ifNil: [ child := MyChildComponent new ]

Also, don't do a html render: child but html render: self child. That way you'll be able to swap components easily.

That way you are sure that child has been properly initialized.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top