Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to transfer parameters from son to Father in WeChat Mini Programs

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

The editor would like to share with you how to transfer parameters from son to father in WeChat Mini Programs. I believe most people don't know much about it, so share this article for your reference. I hope you will learn a lot after reading this article. Let's learn about it!

How the child page of the Wechat applet passes parameters to the parent page

Sometimes when we are working on a WeChat Mini Programs project, we will encounter the following situation: there is a list page, and the page has a filter condition. After clicking, we jump to the page, select the conditions, and return to the list page after selection. Query the data according to the filter criteria. In general, more often than not, what we see is processed by screening criteria in the form of a pop-up box. So if we just want to jump to the interaction of the page, how do we pass the parameters from the child page to the parent page?

problem

Wx.navigateBack cannot carry parameters, and child pages cannot pass parameters to the parent page.

Child pages manipulate parent page data

Notice in this place that we are talking about child pages manipulating the data of the parent page.

There is an API of getCurrentPages on the official document (described below on the official website):

PageObject [] getCurrentPages () gets the current page stack. The first element in the array is the front page, and the last element is the current page.

Do not try to modify the page stack, which will result in routing and page state errors.

Do not call getCurrentPages () when App.onLaunch, when the page has not yet been generated.

Through the API of getCurrentPages, we can get the data of the page stack, so we can get the specified page. In the child page, by modifying the data of the parent page, we can achieve the function of passing parameters from the child page to the parent page.

Const pages = getCurrentPages (); const gotoPage = pages [pages.length-1]

So pages [pages.length-1] is the current page, the parent page is pages [pages.length-2], and so on, we can get other ancestor pages.

Then use the setData method gotoPage.setData ({xxx:'}) to modify the data that sets the parent page so that the child page passes parameters to the parent page. After that, you can return the page through wx.navigateBack.

Other solutions

module

Bounce frame

As mentioned at the beginning of our article, if you need to pass parameters from the child page to the parent page, then we can display the content in the form of a pop-up box, and hide the current pop-up box or component after selecting the corresponding data.

The above is all the contents of the article "how to transmit parameters from son to Father in WeChat Mini Programs". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report