Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Advanced Data Controls Guide Clarification #1345

Open
codezan opened this issue Oct 30, 2021 · 1 comment
Open

Advanced Data Controls Guide Clarification #1345

codezan opened this issue Oct 30, 2021 · 1 comment

Comments

@codezan
Copy link

codezan commented Oct 30, 2021

``I'm having trouble figuring out how ListView should work using the ListCellFragment described by the guide in the Advanced Data Controls chapter (https://edvin.gitbooks.io/tornadofx-guide/content/part2/Advanced_Data_Controls.html)

It creates the ListView like so:

listview(personlist) {
    cellFragment<PersonCellFragment>()
}

But then talks about the class PersonListFragment, not PersonCellFragment

Furthermore, in PersonListFragment, the data is bound to an intermediary of the Person model called PersonModel, which itself is explained in the chapter Editing Models and Validation (https://edvin.gitbooks.io/tornadofx-guide/content/part1/11_Editing_Models_and_Validation.html) but it does not have an empty constructor, so how is the binding shown in the example even possible?

class PersonListFragment : ListCellFragment<Person>() {
    val person = PersonModel().bindTo(this)
    ...

Why is this PersonModel even necessary? Can't the form elements bind to the Person instance itself, since the Model seems to be doing nothing but declaring new properties that are bound to the Person properties anyhow. What's the point of doing that?

@SchweinchenFuntik
Copy link
Contributor

the documentation explains the motives behind Model.

ListCell ( ListCellFragment) is reused, and one instance can have different instances of Person. Therefore, you need to clear the data, states and bindings to Person.

But this mechanism is already implemented in Model. When changing person in PersonModel it will automatically update the bindings

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants