Hi,
I wanted to point you to the new Spec book (
http://files.pharo.org/books-pdfs/spec/2017-01-23-SpecBooklet.pdf ), but
apprently it's not there.
Many Spec widgets have examples accompanying them, so always check class side
(not for all though). For TreeModel you can see couple there - good for playing
around; e.g.
exampleWithNoSpecifiedNodes
"self exampleWithNoSpecifiedNodes"
TreeModel new
roots: (1 to: 5);
childrenBlock: [ :item | 1+item to: 5+item ];
openWithSpec
You specify the initial data (root nodes) via the `roots:` message.
The `childrenBlock:` then specifies how one would retrieve data given a
particular node; note that this applies to _any node_, not just the root ones;
so you can have potentially infinitely deep trees.
A more complex example could be this (this is awful code for demonstration only
;):
TreeModel new
roots: {#parent. #childless. 20. #root -> #(a b c)};
childrenBlock: [ :item |
item isSymbol ifTrue: [
item = #parent
ifTrue: [ #(child1 child2) ]
ifFalse: [ #() ]
] ifFalse: [
item isNumber
ifTrue: [ {item + 2. item ** 2} ]
ifFalse: [ "association" item value ]
]
];
openWithSpec
Peter
On Sat, Apr 01, 2017 at 06:49:41AM -0700, chrismihaylyk wrote:
> Hi!
>
> Could anyone explain me how works childrenBlock: method from TreeModel?
> step-by-step.
> What data it operates? How makes a result?
>
> Thanks a lot? Khrystyna.
>
>
>
>
>
> --
> View this message in context:
> http://forum.world.st/How-childrenBlock-in-TreeModel-works-tp4940884.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>