在 TornadoFX 中,如何在 ItemViewModel 的可为 null 的 属性 上 select 深层嵌套 属性?
In TornadoFX, how can I select a deeply-nested property on an nullable property of an ItemViewModel?
TornadoFX 有一个 select
函数,用于访问 属性 中的 属性。例如,用法为:
textfield(viewModel.customerProperty.select(Customer::nameProperty))
这很好用,但是,如果 customerProperty
的值可以为空(Customer?
),select
不起作用,因为它期望非空反对 "select" from.
万一Property
有nullable
值,select
怎么用呢?
即使 属性 可以包含 null,您也不需要将类型声明为可为 null。只需更改 属性 的类型即可。
TornadoFX 有一个 select
函数,用于访问 属性 中的 属性。例如,用法为:
textfield(viewModel.customerProperty.select(Customer::nameProperty))
这很好用,但是,如果 customerProperty
的值可以为空(Customer?
),select
不起作用,因为它期望非空反对 "select" from.
万一Property
有nullable
值,select
怎么用呢?
即使 属性 可以包含 null,您也不需要将类型声明为可为 null。只需更改 属性 的类型即可。