search
HomeWeChat AppletWeChat DevelopmentAn introduction to several methods of passing and retrieving values ​​in WeChat development

This article mainly introduces the relevant information summarized by several methods of transferring and obtaining values ​​​​in WeChat mini programs. Here are detailed explanations of these methods, and sample codes are attached. Friends in need can refer to it

WeChat applet passing value

The common values ​​​​in the applet are as follows. If you write down a complete project, the probability of using it is almost 100%.

  • List index subscript value

  • Page value passing

  • form form value

1. List index subscript value

The implementation method is: data-index="{{index}}" digging and e .currentTarget.dataset.index to fill in the pit

1.1 Generate value

<image src="../../../images/icon_delete.png" /><text>删除</text>

Add data-index="{{index}}" custom attributes and bindings to the delete icon and text Click event bindtap="delete"

<image src="../../../images/icon_delete.png" /><text>删除</text>

implement the delete method and get the index subscript value.


delete: function (e) {
  var index = parseInt(e.currentTarget.dataset.index);
  console.log("index" + index);
}

What happens if e.target is used instead of e.currentTarget?

will cause the index value to be output only if the is clicked, and the click element or will output NaN.

What is the use of target? It is used to distinguish sub-elements from external elements when they need to be processed separately. For example, when changing the user's avatar, click on the avatar itself to preview the large image, and Click the entire line where the avatar is to switch the avatar.

1.2 Get the value

Try to find the deletion address of the corresponding element from the index data


// 找到当前地址AVObject对象
var address = that.data.addressObjects[index];
// 给出确认提示框
wx.showModal({
  title: &#39;确认&#39;,
  content: &#39;要删除这个地址吗?&#39;,
  success: function(res) {
    if (res.confirm) {
      // 真正删除对象
      address.destroy().then(function (success) {
        // 删除成功提示
        wx.showToast({
          title: &#39;删除成功&#39;,
          icon: &#39;success&#39;,
          duration: 2000
        });
        // 重新加载数据
        that.loadData();
      }, function (error) {

      });
    }
  }
})

2. Page value passing

Pass the address id from the shipping address list page to the editing page to read the original address for modification.

The address/list page implements the following code


<view class="container" data-index="{{index}}" bindtap="edit"><image src="../../../images/icon_edit.png" /><text>编辑</text></view>

edit: function (e) {
  var that = this;
  // 取得下标
  var index = parseInt(e.currentTarget.dataset.index);
  // 取出id值
  var objectId = this.data.addressObjects[index].get(&#39;objectId&#39;);
  wx.navigateTo({
    url: &#39;../add/add?objectId=&#39;+objectId
  });
},

The address/add page implements the onLoad(options) method, from the url path Get the objectId

onLoad: function (options) {
  var objectId = options.objectId
}

and then access the network and render the page.

3. Form form value

3.1 Method 1, through

and

The above is the detailed content of An introduction to several methods of passing and retrieving values ​​in WeChat development. 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 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),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor