witt
witt
  • 发布:2017-03-21 15:43
  • 更新:2017-03-21 15:43
  • 阅读:1171

动态创建navbar里面的内容

分类:HTML5+

下面是我创建navbar的代码

var subpages_id = ['index', 'praise', 'friends', 'my'];
var subpages_page = ['index.html', 'praise.html', 'friends.html', 'my.html'];
var subpage_style = {
top: '0',
bottom: '51px',
scrollIndicator: 'none',
hardwareAccelerated: true
};
var aniShow = {};
//创建子页面,首个选项卡页面显示,其它均隐藏;
mui.plusReady(function() {
var self = plus.webview.currentWebview();
if(self.children().length <= 5) {
for(var i = 0; i < 5; i++) {
var temp = {};
var sub = plus.webview.create(subpages_page[i], subpages_id[i], subpage_style);
if(i > 0) {
sub.hide();
} else {
temp[subpages_id[i]] = "true";
mui.extend(aniShow, temp);
}
self.append(sub);
}
}
});
//当前激活选项
var activeTab = subpages_id[0];
//选项卡点击事件
mui('.mui-bar-tab').on('tap', 'a.mui-tab-item', function(e) {
var newactiveTab = activeTab;
var targetTab = this.getAttribute('data-href');
if(targetTab == activeTab) return;
//显示目标选项卡
if(mui.os.ios || aniShow[targetTab]) {
plus.webview.show(targetTab);
} else {
var temp = {};
temp[targetTab] = "true";
mui.extend(aniShow, temp);
plus.webview.show(targetTab, "fade-in", 250);
}
var current_webview = plus.webview.getWebviewById(activeTab);
if(current_webview.id == "index") {
var web = plus.webview.getWebviewById("index_sub.html");
web.evalJS("popover_hide();")
} else {
current_webview.evalJS("popover_hide();");
}
//更改当前活跃的选项卡
activeTab = targetTab;
});

我用后台传过来的数据动态的改变

var subpages_id = ['index', 'praise', 'friends', 'my'];
var subpages_page = ['index.html', 'praise.html', 'friends.html', 'my.html'];

的值

在下面这段代码之前还能读到activeTab的值为index 但是到这里就报错了 current_webview not defined

我想问一下 这个是为什么 ????? 难道这个里面的值必须是固定的 还是我给的不对 或者是别的什

么原因??????

var current_webview = plus.webview.getWebviewById(activeTab);
if(current_webview.id == "index") {
var web = plus.webview.getWebviewById("index_sub.html");
web.evalJS("popover_hide();")
} else {
current_webview.evalJS("popover_hide();");
}

2017-03-21 15:43 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复