我在将ComboBox.selectionModelProperty
连接到ViewModel时遇到麻烦。
问题在于该属性的类型为SingleSelectionModel
,这是一个接口,并非真正易于实例化。我的想法是在ViewModel中实例化一个ObjectProperty<SingleSelectionModel>
,然后将其绑定到ComboBox.selectionModelProperty
。
class ViewModel {
val selectedService = new SimpleObjectProperty[SingleSelectionModel[ServiceId]]()
..
// I want to set an initial value but now I have a problem..
// there's no easy way of instantiating a SingleSelectionModel
// without resorting to roll out my own implementation of a
// SingleSelectionModel.
}
SingleSelectionModel
,但在我看来,API并非真正针对此目的。是吗?谢谢!