我有非常简单的视图index.xml
<Alloy>
<Window id="byFav">
<TableView id="tableByFav" />
</Window>
<Alloy>
在这个程序中我想打开webView并使用它代替tableByFav View 当你点击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 );
}
但我不确定它是否遵守合金的概念。
我试图理解合金的概念。
答案 0 :(得分: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
});
}
要使用Alloy执行此操作,您可以为名为(entryWindow.xml
)的webview创建一个控制器,如下所示:
<Alloy>
<Window id="entryWindow">
<WebView id="entryView" />
</Window>
<Alloy>
在控制器(entryWindow.js
)中,您可以从提供的参数中设置URL:
$.entryView.url = arguments[0].url;
现在在索引控制器中,您将打开webview,如下所示:
$.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
});
}