你的組件是提供給您自己的網頁中的變量,你可以訪問你的頁面內所需的變量,像這樣:
@Component(id = "myComponent")
private MyComponent myComponent;
@SetupRender //or any other render event method
private void setup() {
Object compVariable = myComponent.getYourVariable();
}
如果你問我是使用事件冒泡,因爲它更優雅如果需要,可以很容易地將一些邏輯重構爲更深的組件。
組件:
@Inject
private ComponentResources resources;
@SetupRender //or any other lifecycle event method
private void triggerEvent() {
Object yourVariable = new Object();
resources.triggerEvent("YOUR_EVENT_NAME", new Object[]{yourVariable}, null);
//add an event callback if needed where I use null here
}
頁:
@OnEvent(value = "YOUR_EVENT_NAME")
private void handleComponentEvent(Object yourVariable) {
//do something with yourVariable
//even return something which would then can be handled by your component callback handler
}
也許不是我現在可以使用,但這是一個不錯的選擇!不知道這是可能的:)。 – Eleeist