tornadoFX 中是否可以将 ListView 绑定(bind)到 ListProperty?
我有一个如下所示的 ViewModel:
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/