gpt4 book ai didi

javafx - 将 ListView 绑定(bind)到 ListProperty

转载 作者:行者123 更新时间:2023-12-02 12:42:44 27 4
gpt4 key购买 nike

在 tornadoFX 中是否可以将 ListView 绑定(bind)到 ListProperty?

我有一个如下 View 模型:

class MyVm: ItemViewModel<Item>() {
val stringProperty = bind { item?.myString?.toProperty() }
}

class MyView: View() {
...
init {
with (root) {
label(myVm.stringProperty)
}
}
}

如果项目更改为 vm.item = Item(...) stringProperty 将相应更新,这将更新所有绑定(bind)标签等...

现在我想对 ListView 做同样的事情:
class MyVm: ItemViewModel<Item>() {
val listProperty = bind { item?.myList?.toProperty() }
}

class MyView: View() {
...
init {
with (root) {
listview {
items = myVm.listProperty
}
}
}
}

但在这种情况下,编译器会提示 listview.items 需要 ObservableList而不是 ListProperty

最佳答案

将您的绑定(bind)定义为 ListProperty 并将 listProperty 传递给 listview 构建器:
val listProperty = bind(Item::myList) as ListProperty<YourType>
..
listview(myVm.listProperty)

关于javafx - 将 ListView 绑定(bind)到 ListProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50260206/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com