js-九宫格与搜索框代码同时存在时出问题
发布于 5 年前 作者 jingzou 7827 次浏览 来自 问答

九宫格js代码

var app = getApp()

var routes = require(‘routes.js’)

Page({

data: {

 userInfo: {},

 cellHeight: ‘120px’,

 pageItems: []

},

//事件处理函数

onLoad: function () {

 var that = this

 console.log(app);

 //调用应用实例的方法获取全局数据  

 app.getUserInfo(function (userInfo) {

  wx.setNavigationBarTitle({

   title: ‘全新测试追踪系统-’ + userInfo.nickName,

   success: function (res) {

    // success

   }

  })

  that.setData({

   userInfo: userInfo

  })

  var pageItems = [];

  var row = [];

  var len = routes.PageItems.length;//重组PageItems

  len = Math.floor((len + 2) / 4) * 4;

  for (var i = 0; i < len; i++) {

   if ((i + 1) % 4 == 0) {

    row.push(routes.PageItems[i]);

    pageItems.push(row);

    row = [];

    continue;

   }

   else {

    row.push(routes.PageItems[i]);

   }

  }

  wx.getSystemInfo({

   success: function (res) {

    var windowWidth = res.windowWidth;

    that.setData({

     cellHeight: (windowWidth / 4) + ‘px’

    })

   },

   complete: function () {

    that.setData({

     pageItems: pageItems

    })

   }

  })

 })

}

})

搜索框js代码

var app = getApp()

var WxSearch = require(’…/…/wxSearch/wxSearch.js’)

Page({

 data: {

   // wxSearchData:{

   //   view:{

   //     isShow: true

   //   }

   // }

 },

 onLoad: function () {

   console.log(‘onLoad’)

   var that = this

   //初始化的时候渲染wxSearchdata

   WxSearch.init(that,43,[‘weappdev’,‘小程序’,‘wxParse’,‘wxSearch’,‘wxNotification’]);

   WxSearch.initMindKeys([‘weappdev.com’,‘微信小程序开发’,‘微信开发’,‘微信小程序’]);

 },

 wxSearchFn: function(e){

   var that = this

   WxSearch.wxSearchAddHisKey(that);

 

 },

 wxSearchInput: function(e){

   var that = this

   WxSearch.wxSearchInput(e,that);

 },

 wxSerchFocus: function(e){

   var that = this

   WxSearch.wxSearchFocus(e,that);

 },

 wxSearchBlur: function(e){

   var that = this

   WxSearch.wxSearchBlur(e,that);

 },

 wxSearchKeyTap:function(e){

   var that = this

   WxSearch.wxSearchKeyTap(e,that);

 },

 wxSearchDeleteKey: function(e){

   var that = this

   WxSearch.wxSearchDeleteKey(e,that);

 },

 wxSearchDeleteAll: function(e){

   var that = this;

   WxSearch.wxSearchDeleteAll(that);

 },

 wxSearchTap: function(e){

   var that = this

   WxSearch.wxSearchHiddenPancel(that);

 }

})

当只有其中一个存在时,程序都正常运行,但当两个同时存在时,程序就报错,帮帮忙,看看哪里出错了

还有就是js中能同时存在两个 pages吗?

回到顶部