【发布时间】:2018-02-09 20:26:59
【问题描述】:
我正在测试 tornadofx 框架(主要是复制粘贴示例),我有一个奇怪的问题,即编辑后表格内容没有更新。我看到了
的内容val persons = FXCollections.observableArrayList<Person>()
val selectedPerson = PersonModel()
正在改变,但视图没有改变。正如我从 tornadofx github 中获取的示例一样,我很困惑。
这里是类
class Person(id: Int, name: String) {
var id by property(id)
fun idProperty() = getProperty(Person::id)
var name by property(name)
fun nameProperty() = getProperty(Person::name)
}
class PersonModel : ItemViewModel<Person>() {
val id = bind { item?.idProperty() }
val name = bind { item?.nameProperty() }
}
class PersonController : Controller() {
val persons = FXCollections.observableArrayList<Person>()
val selectedPerson = PersonModel()
init {
// Add some test persons for the demo
persons.add(Person(42, "John Doe"))
persons.add(Person(43, "Jane Doe"))
}
}
class MainWindow : View("FX Test") {
private val controller: PersonController by inject()
override val root = borderpane {
center = tableview(controller.persons) {
column("ID", Person::id)
column("Name", Person::name)
bindSelected(controller.selectedPerson)
contextmenu {
item("Edit", KeyCombination.keyCombination("F3")).action {
dialog("Client editor") {
field("Name") {
textfield(controller.selectedPerson.name)
}
buttonbar {
button("Save") {
setOnAction {
controller.selectedPerson.commit()
close()
}
}
}
}
}
}
}
}
}
根据文档,在控制器提交后,视图会自动更新。
【问题讨论】:
标签: tornadofx