Get the App
SLTechnology News&Howtos  ›  Development  › 

How to transfer values from child pages to parent pages in WeChat Mini Programs

Shulou Source: shulou.com Published: 2022-05-31 22:59:56 09月21日 Update

This article mainly introduces WeChat Mini Programs in how to achieve the child page to the parent page of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this WeChat Mini Programs article on how to transfer the value of the child page to the parent page. Let's take a look.

A detailed explanation of the example of WeChat Mini Programs's sub-page transmitting values to the parent page

The above picture is the edit payment page, and the bottom picture is the sub-page that opens after clicking the icon to select a friend on the edit payment page. At this time, when you click on a friend of the child page, you need to pass the friend's name back to the edit payment parent page.

The approach taken is:

Get and manipulate the target Page object directly from the page routing stack. In this way, the information of the current page routing stack is obtained by calling API: getCurrentPages () of Mini Program. The corresponding Page object is stored in this routing stack according to the routing order of the page. We can easily get the complete Page object of the page above, which makes it possible to directly call the properties and methods of the Page object.

The code of the selected friend page is as follows:

Var pages = getCurrentPages (); var currPage = pages [pages.length-1]; / / currently select friend page var prevPage = pages [pages.length-2] / / the last edit payment page / / directly call the setData () method of the previous page to save the data to the edit payment page to prevPage.setData ({name: currentfriend.name / / the currently selected friend name is assigned to the name temporary variable in the edit payment}) This is the end of the article on "how to transfer values from the child page to the parent page in WeChat Mini Programs". Thank you for your reading! I believe that everyone has a certain understanding of the knowledge of "how to transfer values from the child page to the parent page in WeChat Mini Programs". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Pages programs friends payments objects routes selections methods knowledge content names articles neutrons codes values information variables icons names instances Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Xiaomi vpn Apple