【发布时间】:2014-10-07 07:08:40
【问题描述】:
我正在尝试使用 Titanium 实现侧面板,其中我在侧面板菜单下有几个选项,每个菜单选项加载不同的视图。其中一个选项加载 web 视图。网站或 html 在 webview 组件中完美加载,但我无法与之交互;从某种意义上说,我无法点击链接或做任何类似的事情。本地和远程 html 都会发生这种情况。
对于侧面板,我正在集成 Ricardo Alcocer 提供的抽屉小部件,链接到他的 github 项目是 -https://github.com/ricardoalcocer/alloy-widget-drawermenu
这里是代码块。
index.xml
<Alloy>
<Window class="container" id="win">
<Require type="widget" src="com.alcoapps.drawermenu" id="drawermenu"/>
</Window>
</Alloy>
mainview.xml(加载 web 视图的侧边菜单选项)
<Alloy>
<View id="mainView">
<View id="mainTopBar">
<View id="menuButton"/>
</View>
<WebView id="chartView" url="http://www.google.co.in"/>
</View>
</Alloy>
menuview.xml(侧面板)
<Alloy>
<View id="menuView">
<View id="menuTopBar"/>
<TableView class="menuTable" id="menuTable">
<TableViewRow class="tableRow" id="row1">
<View id="rowContainer">
<View id="rowSkull" class="rowIcon"/><Label id="rowLabel" class="rowLabel">MainView</Label>
</View>
</TableViewRow>
<TableViewRow class="tableRow" id="row2">
<View id="rowContainer">
<View id="rowGear" class="rowIcon"/><Label id="rowLabel" class="rowLabel">Settings</Label>
</View>
</TableViewRow>
</TableView>
</View>
</Alloy>
index.js
var controls=require('controls');
// get main and menu view as objects
var menuView=controls.getMenuView();
var mainView=controls.getMainView();
// attach event listener to menu button
mainView.menuButton.add(controls.getMenuButton({
h: '60',
w: '60'
}));
//Minor changes to click event. Update the menuOpen status;
mainView.menuButton.addEventListener('click',function(){
$.drawermenu.showhidemenu();
$.drawermenu.menuOpen=!$.drawermenu.menuOpen;
}); // method is exposed by widget
// get config view as objects
var configView=controls.getConfigView();
//add menu view to ConfigView exposed by widget
configView.menuButton.add(controls.getMenuButton({
h: '60',
w: '60'
}));
//Minor changes to click event. Update the menuOpen status;
configView.menuButton.addEventListener('click',function(){
$.drawermenu.showhidemenu();
$.drawermenu.menuOpen=!$.drawermenu.menuOpen;
}); // method is exposed by widget
$.drawermenu.init({
menuview:menuView.getView(),
mainview:mainView.getView(),
duration:200,
parent: $.index
});
//variable to controler de open/close slide
var activeView = 1;
// add event listener in this context
menuView.menuTable.addEventListener('click',function(e){
$.drawermenu.showhidemenu();
$.drawermenu.menuOpen = false; //update menuOpen status to prevent inconsistency.
if(e.rowData.id==="row1"){
if(activeView!=1){
$.drawermenu.drawermainview.remove(configView.getView());
activeView = 1;
} else {
activeView = 1;
}
}
if(e.rowData.id==="row2"){
if(activeView!=2){
$.drawermenu.drawermainview.add(configView.getView());
activeView = 2;
} else{
activeView = 2;
}
}
// on Android the event is received by the label, so watch out!
Ti.API.info(e.rowData.id);
});
$.index.open();
controls.js
var Alloy=require('alloy');
exports.getMainView=function(){
return Alloy.createController('mainview');;
};
exports.getMenuView=function(){
return Alloy.createController('menuview');
};
exports.getMenuButton=function(args){
var v=Ti.UI.createView({
height: args.h,
width: args.w,
backgroundColor: '#A1D0E0'
});
var b=Ti.UI.createView({
height: "20dp",
width: "20dp",
backgroundImage: "/106-sliders.png"
});
v.add(b);
return v;
};
//Get the Configuration Controller
exports.getConfigView=function(){
return Alloy.createController('config');
};
我没有提供设置页面(第二个侧面板菜单选项)的代码块以及我认为不应该导致问题的样式表。
我看过Titanium Studio Webview not letting me interact with website 但这对我没有帮助。我需要有这样的实现,我认为当然应该有一些解决方法。
我们将不胜感激任何形式的帮助。谢谢。
【问题讨论】:
标签: titanium-mobile titanium-alloy titanium-modules titanium-widgets