我正在製作不含聚合物的自定義元素,我不使用HTML標記。因此,我必須構建內部元素並在運行時附加它。 MyComponent只是經典的View。我可以設置一些數據{val: 97.0, unit: '%'}
,組件顯示它。什麼是創建和附加兒童的最佳時間?
所有初始化我在attached
或domReady
事件(我仍然沒有得到最好的地方)。在這裏,我可以將數據設置爲附加的實際元素('97 .0%'到span元素)。
所以,我可以在構造函數中MyComponent.created()
創建內部元素,在attached
事件,在domReady
事件或曾經在工廠的構造是這樣的:
factory MyComponent (data) {
var component = new Element.tag('my-component');
component.data = data;
component.children.add(
new Element.span()
..classes.toggle('display', true)
);
return component;
}
這裏是一個問題:哪裏是最好的地方:
- 構建元素與
new Element.tag('my-component');
; - 設置它的風格,類等屬性;
- 將它附加到`children.add(component);?
謝謝。
有在標題笑話的地方。 – ViRALiC
你是指無限循環問題嗎?我不知道這件事。 – kelegorm