2013-04-23 17 views
1

試圖建立一些簡單的應用程序與框架,有一個問題:如何找到與查看ID

  • 是否有可能找到View分層佈局裏面?如何 ? (在Dart中)

    Rikulo網站上有一些關於IdSpace的文檔,但我不太明白如何使用它。 I延伸ViewIdSpace?或者View會自動生成Id?

更新(添加的代碼示例)

/* 
* Function will actualy build View 
*/ 
void _buildUi(Element tagElement) 
{ 
    View mainView = new View(); 
    mainView.profile.width = '100%'; 
    mainView.profile.height = '100%'; 
    mainView.layout.type = 'linear'; 
    mainView.layout.orient = 'vertical'; 
    mainView.style.cssText = "background: yellow;"; 

    View vWorkSpace = new View(); 
    vWorkSpace.profile.width = 'flex'; 
    vWorkSpace.profile.height = 'flex'; 
    vWorkSpace.layout.type = 'linear'; 
    vWorkSpace.layout.orient = 'horizontal'; 
    vWorkSpace.style.cssText = "background: red;"; 

    // 
    // Left menu 
    View vLeftBar = new View(); 
    vLeftBar.profile.width = "10%"; 
    vLeftBar.profile.height = "10%"; 
    vLeftBar.layout.type = 'linear'; 
    vLeftBar.layout.orient = 'vertical'; 
    vLeftBar.layout.spacing = '10'; 

    View vLogo = new View(); 
    vLogo.addChild(new Image('images/google_chrome.png')); 
    vLeftBar.addChild(vLogo); 

    Button vButton = new Button(); 
    vButton.text = 'Sign in with Google'; 
    vLeftBar.addChild(vButton); 
    vButton.on.click.add((e){  // Somehow I get an error here: Method 'add' not defined for class 'Stream' 
     broadcaster.send(new ViewEvent('foo')); 
    }); 

    vWorkSpace.addChild(vLeftBar); 

    mainView.addChild(vWorkSpace); 
    mainView.addToDocument(ref: tagElement, layout: true); 
} 

在dart.app另一個地方處理vButton click事件時。我如何找到(在代碼中)vLogo視圖?

回答

0

代碼檢索查看最簡單的辦法就是給它一個id:

View vLogo = new View(); 
vLogo.id = "vLogo"; 

然後,在你的事件偵聽器,使用query訪問它:

button.query("#vLogo"); // returns vLogo 

然而,在你的情況下,你將能夠直接訪問事件監聽器關閉中的vLogo實例。

0

當然,像Element一樣,View提供了基於CSS選擇器的檢索,名爲queryqueryAll。您可以使用它們在檢索DOM元素時檢索視圖。

一般來說,您不必擔心IDSpace,除非您想在不同的視圖中使用相同的ID。層次樹本身就是一個ID空間。如果一個視圖實現IDSpace,它將形成另一個ID空間。

+0

任何代碼示例都不錯 – Jasper 2013-04-24 06:24:06

+0

有關[IDSpace](http://docs.rikulo.org/ui/latest/Views/Fundamentals/ID_Space_and_Query.html)的更多信息。 – simonpai 2013-04-25 01:57:58