向我展示了如何使用类似Val.selectVar(property, propertyOfProperty)
. 但是,我想知道如何继续在组合图上创建依赖项。就像财产的财产等一样。
这是我所知道的和我想要的示例:
import org.reactfx.value.Val;
import org.reactfx.value.Var;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
class Level1 {
private ObjectProperty<Level2> l2 = new SimpleObjectProperty<>(new Level2());
ObjectProperty<Level2> l2Property() { return l2; }
}
class Level2 {
private ObjectProperty<Level3> l3 = new SimpleObjectProperty<>(new Level3());
ObjectProperty<Level3> l3Property() { return l3; }
}
class Level3 {
private ObjectProperty<Level4> l4 = new SimpleObjectProperty<>(new Level4());
ObjectProperty<Level4> l4Property() { return l4; }
}
class Level4 {
private IntegerProperty ip = new SimpleIntegerProperty();
IntegerProperty ipProperty() { return ip; }
}
public class Example3 {
Example3() {
Level1 l1 = new Level1();
Level2 l2 = l1.l2Property().get();
Level3 l3 = l2.l3Property().get();
Level4 l4 = l3.l4Property().get();
Var<Number> ipVar = Val.selectVar(l3.l4Property(), Level4::ipProperty);
ipVar.addListener((ob, o, n) -> System.out.println(o + " -> " + n));
l4.ipProperty().set(1); // prints "0 -> 1"
Level4 newL4 = new Level4();
newL4.ipProperty().set(2);
l3.l4Property().set(newL4); // prints "1 -> 2"
// Something that does this
// ipVar2.listenTo(l2.l3Property(), l1.l2Property());
// or this
// Var<Number> ipVar2 = Val.selectVarAll(l1.l2Property(), l2.l3Property(), l3.l4Property(), Level4::ipProperty);
Level3 newL3 = new Level3();
l2.l3Property().set(newL3); // I want: prints "2 -> 0"
// level2 etc.
}
public static void main(String[] args) {
new Example3();
}
}
基本上,我想知道一个属性何时会因包含它的属性中的任何位置而发生变化,而不仅仅是直接的。