我想实现一个使用钛的侧面板,其中我有两个选项在侧面板菜单下,每个菜单选项加载不同的视图。其中一个选项加载webview。网站或html在webview组件中完美加载,但我无法与它互动;因为我无法点击链接或做任何事情。这与本地以及远程html都会发生。钛SDK的webview组件不允许与它加载的网站的交互
对于侧板,我被里卡多阿尔科塞尔提供的抽屉部件,链接整合到自己的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(侧菜单选项加载网页视图)
<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 但它对我的情况没有帮助。我需要有这种实现,我认为肯定应该有一些解决方法。
任何形式的帮助将被高度赞扬。谢谢。
我面临同样的问题,你的回答帮了我很多!感谢分享=) – 2017-02-24 11:56:05
很高兴听到它帮助你。 @CarlosHenriqueLustosa – letsbondiway 2017-02-25 13:12:50