动态tabbar在IOS下不显示
发布于 6 年前 作者 xiulan76 3740 次浏览 来自 问答

  因为业务需要,所以需要两套tabbar。所以编写了个动态的tabbar。实现逻辑是仿造在app.json里配置的json的格式,在app.js的globalData里写好对应的json(tabbar1和tabbar2),然后用函数触发,使用哪一个tabbar。

  测试了两台iPhone的效果

  +++++++++++++++++++++++++++++++++++++++++++++++++

          A iphone  版本号 10.2    微信号  6.5.15

          B iphone 版本号  11.2    微信号  6.5.7

   +++++++++++++++++++++++++++++++++++++++++++++++++

  在A机器测试显示,(PS: A机器之前没测试过)

  在B机器上不显示,不知道是不是因为自己封装的原因。检查完代码想不出来问题,就把小程序删了,然后重新扫码进入,第一次是正常的,然后第二次,就又不显示tabbar了。A、B机器都这样操作,结果一样。

    报的错误都是: undefined is not an object (evaluating ‘o.list.length’);at App editTabBar function


问题可能性:

1.版本的原因。。。已经排除,因为A和B iPhone都都试过了,都是在第二次进入时报这个错误

2.代码的问题。。。实在没想出来什么问题

editTabBar: function (barType) {
 var _curPageArr = getCurrentPages();
 var _curPage = _curPageArr[_curPageArr.length - 1];
 var _pagePath = _curPage.__route__;
 if (_pagePath.indexOf('/') != 0) {
   _pagePath = '/' + _pagePath;
 }
 let tabBar = this.globalData.tabBar1;
 console.log("tabbar.list" + tabBar.list);
 console.log("tabbar.list的类型" + typeof tabBar.list);
 if (barType != null && barType != "undefined") {
   if (barType == 1) {
     tabBar = this.globalData.tabBar2;
   }
 } else {
   wx.getStorage({
     key: 'barType',
     success: function (res) {
       tabBar = res.data;
     },
   })
   if (barType == 1) {
     tabBar = this.globalData.tabBar2;
   }
 }
 let length = tabBar.list.length;
 if (length > 0 ){
   for (let i = 0; i < length; i++) {
     tabBar.list[i].active = false;
     if (tabBar.list[i].pagePath == _pagePath) {
       tabBar.list[i].active = true;//根据页面地址设置当前页面状态
     }
   }
 }
 _curPage.setData({
   tabBar: tabBar
 });
回到顶部