2014-02-10 24 views
2

我有很簡單的觀點INDEX.XML如何處理動態創建的視圖合金XML

<Alloy> 
    <Window id="byFav"> 
     <TableView id="tableByFav" /> 
    </Window> 
<Alloy> 

在這個節目,我想打開web視圖,當你點擊tableByFav使用,而不是tableByFav查看 。

我不知道如何在xml中描述這個過程。

所以我在這樣的index.js中編寫代碼。

$.tableByFav.addEventlistener('click',function(e){ 
    entryWindow = Titanium.UI.createWindow({ 
     title: "window" 
    }); 
    entryView = Titanium.UI.createWebView({ 
     url: "google.com" 
    }); 
    entryWindow.add(entryView); 
    $.byFav.open(entryWindow); 
} 

但是我不確定它是否服從合金的概念。

我想了解合金的概念。

回答

2

您正在打開錯誤的窗口,試試這個:

$.tableByFav.addEventlistener('click',function(e){ 
    var entryWindow = Titanium.UI.createWindow({ 
     title: "window" 
    }); 
    var entryView = Titanium.UI.createWebView({ 
     url: "http://www.google.com" 
    }); 
    entryWindow.add(entryView); 
    // Call open on the entry window itself 
    entryWindow.open({ 
     modal : true // Set to true if you want an opening animation 
    }); 
} 

要與合金做到這一點,您可以創建一個名爲(entryWindow.xml)這樣的web視圖控制器:

<Alloy> 
    <Window id="entryWindow"> 
     <WebView id="entryView" /> 
    </Window> 
<Alloy> 

並且在控制器(entryWindow.js)中,您可以使用提供的參數設置url:

$.entryView.url = arguments[0].url; 

現在索引中的控制器,你會打開網頁流量是這樣的:

$.tableByFav.addEventlistener('click',function(e){ 
    // Create a controller, pass url argument 
    var controller = Alloy.createController('entryWindow', {url: "http://www.google.com"}); 
    // Get the controller's view (a window) and open it 
    controller.getView().open({ 
     modal : true // Set to true if you want an opening animation 
    }); 
} 
+0

感謝您的指示非常明確 – whitebear

+0

我已經按照你做的代碼。 – whitebear