我得到的数据格式是一个
因为我需要使用Map集合中的数据(避免重复和其他原因),所以我想知道是否可以绑定这2个集合。
类似于下面的代码:
ObservableMap<T, Foo>
。
为了在视图中实现这些数据,我需要将该映射的值以ObservableList<Foo>
的格式呈现。因为我需要使用Map集合中的数据(避免重复和其他原因),所以我想知道是否可以绑定这2个集合。
类似于下面的代码:
ObservableMap<Integer, Foo> data = FXCollections.observableHashMap();
ObservableList<Foo> target = FXCollections.observableArrayList();
// Won't work
Bindings.bindContent(target, data.values());
数据会在运行时发生变化,因此需要绑定。
编辑: 使用映射值初始化列表无法正常工作,因为将有其他Foo添加到映射中: 例如,使用字符串作为映射值的示例:
ObservableMap<Integer, String> map = FXCollections.observableHashMap();
map.put(1, "a");
map.put(2, "b");
ObservableList<String> list = FXCollections.observableArrayList(map.value());
//map = {1=a, 2=b}
//list = [a, b]
// ok
map.put(3, "c");
//map = {1=a, 2=b, 3=c}
//list = [a, b]
// no update