Home > WeChat Applet > Mini Program Development > How to use Map objects in WeChat applet development

How to use Map objects in WeChat applet development

php中世界最好的语言
Release: 2018-06-05 13:36:15
Original
6919 people have browsed it
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 }) },
Copy after login

In this way, the optimization of the tab will be reassigned if the interface data becomes too much. Although I am adding drama to myself, this is also my work attitude. I have learned new things and optimized the project.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Using rpx for WeChat mini program development

##How to create a page for WeChat mini program development

The above is the detailed content of How to use Map objects in WeChat applet development. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template