gpt4 book ai didi

treeview - 如何使用 TornadoFX TreeView 显示数据

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

我正在学习如何使用 kotlin 并已开始使用tornadoFX。我正在阅读该指南以尝试学习它,但是我无法弄清楚“具有不同类型的 TreeView”中的含义。似乎是说我应该使用星形投影,据我所知,当您在调用中使用 * 时。

但是,一旦我这样做, TreeView 就会显示“不允许在函数和属性的类型参数上进行投影”

这是我的代码:

类 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
}
}
}

关于treeview - 如何使用 TornadoFX TreeView 显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46426488/

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