如何使用TornadoFX树视图显示数据

我正在学习如何使用kotlin并开始使用tornadoFX。 我正在通过指南来试图学习它,但是我无法弄清楚“具有不同类型的TreeView”是什么意思。 这似乎是说,我应该使用星形投影,这是我知道,当你在呼叫中使用*。

然而,只要我这样做,树视图说'功能和属性的类型参数不允许投影'

这是我的代码:

class MainView:View(“”){

override val root = treeview<*> { root = TreeItem(Person("Departments", "")) cellFormat { text = when (it) { is String -> it is Department -> it.name is Person -> it.name else -> throw IllegalArgumentException("Invalid Data Type") } } populate { parent -> val value = parent.value if (parent == root) departments else if (value is Department) persons.filter { it.department == value.name } else null } } } 

我真的很难过,我不知道我的意思。

此外,如果任何人可以提供给我一些有用的链接学习Kotlin和TornadoFX它将不胜感激:)

看来这个指南实际上是不正确的。 我得到它使用treeview<Any>

 data class Department(val name: String) data class Person(val name: String, val department: String) val persons = listOf( Person("Mary Hanes", "Marketing"), Person("Steve Folley", "Customer Service"), Person("John Ramsy", "IT Help Desk"), Person("Erlick Foyes", "Customer Service"), Person("Erin James", "Marketing"), Person("Jacob Mays", "IT Help Desk"), Person("Larry Cable", "Customer Service") ) val departments = persons.groupBy { Department(it.department) } override val root = treeview<Any> { root = TreeItem("Departments") cellFormat { text = when (it) { is String -> it is Department -> it.name is Person -> it.name else -> kotlin.error("Invalid value type") } } populate { parent -> val value = parent.value when { parent == root -> departments.keys value is Department -> departments[value] else -> null } } } 
Interesting Posts