Home > Article > WeChat Applet > In-depth understanding of WeChat applet data binding
This article mainly introduces the relevant information about the detailed introduction of data binding of WeChat mini program. Friends who need it can refer to it
Data binding includes some of the first few It looks okay, but some of the following ones may not be understood, and some of the data displayed on the interface cannot be displayed due to conditions. If you don't understand it, you can remember it first, and you will understand it when you actually use it later. Anyway, this is what I think. Record it here first
data.wxml
##
<!--数据绑定使用对象---内容--> <view>{{message}}</view> <!--数据绑定使用对象---组件属性---需要在双引号之内--> <view id="item-{{id}}">组件属性</view> <!--数据绑定使用对象---控制属性---需要在双引号之内--> <view wx:if="{{condition}}">控制属性</view> <!--数据绑定使用对象---三元运算--> <view hindden="{{flag ? true : false}}">三元运算符</view> <!--数据绑定使用对象---算数运算--> <view>我是运算结果---{{a + b}} + {{c}} + d</view> <!--数据绑定使用对象---逻辑判断--> <view wx:if="{{length > 5}}">asdf</view> <!--数据绑定使用对象---字符串运算--> <view>{{"Hello " + name}}</view> <!--数据绑定使用对象---数组组合--> <view wx:for="{{[zero, 1, 2, 3, 4, 5, 6]}}">{{item}}</view> <!--数据绑定使用对象---对象--> <template is="objectCombine" data="{{for: x, bar: y}}"></template> <!--数据绑定使用对象---扩展运算符对象 ... 将一个对象展开--> <template is="objectCombine" data="{{...obj1, ...obj2, p: 5}}"></template> <!--数据绑定使用对象---对象的key和value相同时--> <template is="objectCombine" data="{{foo, bar}}"></template>
data.js
Page({ data:{ //内容绑定 message: 'Hello WeApp', //组件属性绑定 id: 0, //控制属性绑定 condition: true, //三元运算 flag:false, //算数运算 a: 1, b: 2, c: 3, //逻辑判断 length: 6, //字符串运算 name: '顺子', //数组组合 zero: 0, //对象 x: 0, y: 1, //对象展开 obj1: { a: 1, b: 2 }, obj2: { c: 3, d: 4 }, p: 5, //对象key和value形同时 foo: 'my-foo', bar: 'my-bar' }, })
The above is the detailed content of In-depth understanding of WeChat applet data binding. For more information, please follow other related articles on the PHP Chinese website!