WeChat applet: data binding explanation

Source: Internet
Author: User
Today, we will introduce the data binding of applets. today's content is followed by the introduction of mini-programs: the basic usage of components. if you are not clear about the content, you can review it on your own. Today, we will introduce the data binding of applets. today's content is followed by the introduction of mini-programs: the basic usage of components. if you are not clear about the content, you can review it on your own.
The text component is introduced in the previous lesson. the example of the previous lesson is as follows:

Case 1: If we want to dynamically display the content in text, we need to use data binding. data binding uses the Mustache syntax (double braces) to wrap the variables, it is identified by {TEXT. Use cases:

 default  primary 
 
  {{text}}
 

We will not see the text content during compilation. at this time, we need to define the text value in the data in newvip. js.

Data: {text: "This is the content of www.html 51.com "},

The compiled result is as follows:

In the same way, on the js page:

 
data:{

On the wxml page, bind data as follows:

 default  {{btnText}} 
 
  {{text}}
 

The results displayed after compilation are as follows:

What should we do if we want to modify the text content after clicking it? Simple

BtnClick: function () {console. log ("The button was clicked...") this. setData ({text: "this is the new 51 applet content "})}

The demo is as follows:

1. after clicking the button, no log is specified and no error message is displayed. There is almost no problem with the naked eye. In fact, there is a space between the bindtap click event bindtap = "btnClick" and>!

 {{btnText}} 

2. the dynamic data in WXML comes from the data of the corresponding Page.

More small programs: data binding related articles please follow the PHP Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.