Home >WeChat Applet >Mini Program Development >Code implementation for modifying data (page data and array data) in WeChat applet
The content of this article is about the code implementation of modifying data (page data and array data) in WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
1. Modify the data of the previous page according to the page stack (that is, modify the data of the previous page on the next page);
let pages = getCurrentPages();//当前页面 let prevPage = pages[pages.length - 2];//上一页面 prevPage.setData({//直接给上移页面赋值 selAddress: true });
The above code will modify the selAddress of the upper-level page Is true;
2. Targeted modification of certain data in the WeChat applet array
数组部分: comdata[ {xhid:8,title:啦啦啦,read_num:100,share_num:20}, {xhid:9,title:嘻嘻嘻,read_num:24,share_num:4}, {xhid:20,title:嘻嘻嘻2,read_num:11,share_num:4}, {xhid:27,title:嗯嗯嗯12,read_num :8,share_num:4}, {xhid:23,title:阿萨飒飒2,read_num:41,share_num:7} ] 代码如下: var index=0; var up = "comdata[" + index + "].share_num"; var newp = ++that.data[0].share_num; that.setData({ [up]:newp })
3. A large collection of the above two pieces of code:
A page jumps to Page B, if you want to modify the data in an array of page A on page B, the code is as follows:
A页面传给B页面share_num和当前的index 在B页面onload赋给 that.setData({ item_index:options.index, share_num:options.share_num }) 然后修改代码: let pages = getCurrentPages();//当前页面 let prevPage = pages[pages.length - 2];//上一页面 var index = that.data.item_index; var up = "comdata[" + index + "].share_num"; var newp = ++that.data.share_num; prevPage.setData({//直接给上移页面赋值 [up]: newp });
Related recommendations:
WeChat applet implements the function of changing the font color by clicking a button
How to dynamically modify label transparency in WeChat applet slider component
The above is the detailed content of Code implementation for modifying data (page data and array data) in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!