### [微信小程序开发中怎样使用Map对象](https://www.prosaas.cn/article/17495) **Published:** 2018-06-05T05:36:15 **Author:** 5201314 **Excerpt:** 这样就实现了,对选项卡的优化,如果接口数据变多了的话,会重新赋值。 虽然是自己给自己加戏,但这是也是我的一种工… let localMap = new Map(),// 定义一个全局的MAP对象  typeCode = ''; // 点击分类里面的细分选项卡 handleClickTabs(e) { let id = e.target.dataset.index,  code = e.target.dataset.id;  typeCode = code;// 这里定义code,在请求回调里面使用  this.setData({ leftTab : id });  if (localMap!=null) {// map对象  let list = localMap.get(typeCode);//获取对应分类的type的code  if (list!=null) {//map里面有值,渲染页面  this.setData({ tabSonList:list }) }else {//map里面没有值,去请求接口 const data = { goodsTypeCode: code };  utils.sendRequest(api.ClassifySon, data, this.handleGoodsSon.bind(this)); }  }else { const data = { goodsTypeCode: code };  utils.sendRequest(api.ClassifySon, data, this.handleGoodsSon.bind(this)); } }, //分类里面的内容 handleGoodsSon(res) { let list = res.data; localMap.set(typeCode,list)//存对应typeCode的list  this.setData({ tabSonList:list }) }, ![](https://user-gold-cdn.xitu.io/2018/5/29/163aa02a3f1b5a82?imageView2/0/w/1280/h/960/format/webp/ignore-error/1) 这样就实现了,对选项卡的优化,如果接口数据变多了的话,会重新赋值。 虽然是自己给自己加戏,但这是也是我的一种工作态度,学习了新东西,还让优化了项目。 相信看了本文案例你已经掌握了方法,更多精彩请关注知企PROSAAS其它相关文章! 推荐阅读: 微信小程序开发rpx使用 微信小程序开发怎样创建页面 以上就是微信小程序开发中怎样使用Map对象的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** 后端开发 ---