search
HomeWeChat AppletWeChat DevelopmentIntroduction to WeChat Development (11) Update the data on the previous page

There is often this demand during the development process of small programs. It is necessary to pass the current page data to the previous page, but wx.navigateBack() cannot pass the data.

The general method is to put the current page data into the local cache, and then take the previous page out of the cache.

In addition, there is another way to make clever use of the page stack.

The getCurrentPages() function is used to obtain the instance of the current page stack, which is given in the form of an array in the order of the stack. The first element is the home page, and the last element is the current page.

The key point is here, get the instance object of the previous page on the current page, and then call the method of the object to complete the data transfer.

Page A

Page({
     data: {
        name: ''
     },
     ...     ,
     //更新name
     changeData: function(name){
        this.setData({
            name: name      
              })   
                }})

Page B, assuming there is a text box for entering a name, click the return button to update the name of page A

Page({
    //此方法用于文本框输入回调
    inputTyping: function (e) {
        //获取页面栈
        var pages = getCurrentPages();
        if(pages.length > 1){
            //上一个页面实例对象
            var prePage = pages[pages.length - 2];
            //关键在这里
            prePage.changeData(e.detail.value)        }
    }})

This way, the data can be passed to For the previous page, please note that page A must use wx.navigateTo to jump to page B, and wx.redirectTo cannot be used. This will close the previous page, causing page B to be unable to obtain the previous page Page instance.

【Related recommendations】

1. WeChat public account platform source code download

2. WeChat voting source code

3. WeChat LaLa Takeaway 2.2.4 Decrypted Open Source Version of WeChat Rubik’s Cube Source Code

The above is the detailed content of Introduction to WeChat Development (11) Update the data on the previous page. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.