In the mini-program tutorial, the dynamic data in WXML comes from the data of the corresponding Page. Data Binding
The dynamic data in WXML comes from the data of the corresponding Page.
Simple binding
Data binding uses the "Mustache" syntax (double braces) to package variables, which can act on:
Content
{Message }}
Page({ data: { message: 'Hello MINA!' } })
Component attributes (must be within double quotation marks)
Page({ data: { id: 0 } })
Control attributes (must be within double quotation marks)
Page({ data: { condition: true } })
Operation
You can perform simple operations within {}. the following methods are supported:
Ternary computation
Hidden
Arithmetic operation
{A + B }}+ {c} + d
Page({ data: { a: 1, b: 2, c: 3 }
The content in the view is 3 + 3 + d.
Logical judgment
String operation
{"Hello" + name }}
Page({ data:{ name:"MINA" } })
Combination
You can also combine them in Mustache to form a new object or array.
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 combination objects are {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 combination objects are {a: 1, B: 2, c: 3, d: 4, e: 5}
If the key and value of an object are the same, it can be indirectly expressed
Page({ data: { foo: 'my-foo', bar: 'my-bar' } })
The final combination object is {foo: 'My-Foo', bar: 'My-bar '}
Note: The preceding method can be combined at will, but if the variable name is the same, the latter will overwrite the former, as shown in figure
Page({ data: { obj1: { a: 1, b: 2 }, obj2: { b: 3, c: 4 }, a: 5 } })
The final combination objects are {a: 5, B: 3, c: 6}
The above is the data binding content of the mini-program tutorial. For more information, see The PHP Chinese website (www.php.cn )!