Javafx 将ListView绑定到ListProperty
在TornadFX中是否可以将ListView绑定到ListProperty 我有一个ViewModel,如下所示:Javafx 将ListView绑定到ListProperty,javafx,kotlin,tornadofx,Javafx,Kotlin,Tornadofx,在TornadFX中是否可以将ListView绑定到ListProperty 我有一个ViewModel,如下所示: class MyVm: ItemViewModel<Item>() { val stringProperty = bind { item?.myString?.toProperty() } } class MyView: View() { ... init { with (root) { label(m
class MyVm: ItemViewModel<Item>() {
val stringProperty = bind { item?.myString?.toProperty() }
}
class MyView: View() {
...
init {
with (root) {
label(myVm.stringProperty)
}
}
}
但在这种情况下,编译器会抱怨listview.items需要一个
ObservableList
而不是ListProperty
将绑定定义为ListProperty并将ListProperty传递给listview生成器:
val listProperty=bind(Item::myList)as listProperty
listview(myVm.listProperty)
完美。我没有意识到listview函数参数采用listProperty。所以我试着分配给项目。
class MyVm: ItemViewModel<Item>() {
val listProperty = bind { item?.myList?.toProperty() }
}
class MyView: View() {
...
init {
with (root) {
listview {
items = myVm.listProperty
}
}
}
}