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 bind dynamic data in WXML

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

Share

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

This article mainly introduces "how to bind dynamic data in WXML". In daily operation, I believe that many people have doubts about how to bind dynamic data in WXML. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to bind dynamic data in WXML". Next, please follow the editor to study!

Data binding

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

Simple binding

Data binding uses "Mustache" syntax (double curly braces) to wrap variables, which can be used to:

Content {{message}} Page ({data: {message: 'Hello Minority'}}) component attributes (need to be within double quotes) Page ({data: {id: 0}}) control attributes (need to be within double quotes) Page ({data: {condition: true}}) keywords (need to be within double quotes)

True of type true:boolean, which represents the true value.

False: false of type boolean, which represents a false value.

Special note: do not directly write checked= "false", the result of the calculation is a string, converted to the boolean type represents the true value.

Operation

You can perform simple operations within {{}}, which are supported in the following ways:

Ternary operation Hidden arithmetic operation {{a + b}} + {c}} + d Page ({data: {a: 1, b: 2, c: 3}})

The content in view is 3 + 3 + d.

Logical judgment string operation {{"hello" + name}} Page ({data: {name: "MINA"}}) data path operation {{object.key} {{array [0]}} Page ({data: {object: {key: 'Hello'}, array: ['MINA']}}) combination

It can also be combined directly within Mustache to form new objects or arrays.

Array {{item}} Page ({data: {zero: 0}})

Finally, it is combined into an array [0,1,2,3,4].

Object Page ({data: {a: 1, b: 2}})

The final object is {for: 1, bar: 2}.

You can also use the extension operator. To expand an object

Page ({data: {obj1: {a: 1, b: 2}, obj2: {c: 3, d: 4})

The final object is {a: 1, b: 2, c: 3, d: 4, e: 5}

If the key and value of an object are the same, it can also be expressed indirectly.

Page ({data: {foo: 'my-foo', bar:' my-bar'}})

The final object is {foo: 'my-foo', bar:'my-bar'}.

Note: the above methods can be combined at will, but if there is a situation with the same variable name, the latter will overwrite the front, such as:

Page ({data: {obj1: {a: 1, b: 2}, obj2: {b: 3, c: 4}, a: 5}})

The final object is {a: 5, b: 3, c: 6}.

Note: if there is a space between curly braces and quotation marks, it will eventually be parsed into a string

{{item}}

Equivalent to

{{item}} at this point, the study on "how to bind dynamic data in WXML" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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