Home > WeChat Applet > Mini Program Development > In-depth understanding of WeChat applet data binding

In-depth understanding of WeChat applet data binding

高洛峰
Release: 2017-03-28 13:43:26
Original
1758 people have browsed it

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

In-depth understanding of WeChat applet data binding

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>
Copy after login

data.js


Page({
 data:{

 //内容绑定
 message: &#39;Hello WeApp&#39;,

 //组件属性绑定
 id: 0,

 //控制属性绑定
 condition: true,

 //三元运算
 flag:false,

 //算数运算
 a: 1,
 b: 2,
 c: 3,

 //逻辑判断
 length: 6,

 //字符串运算
 name: &#39;顺子&#39;,

 //数组组合
 zero: 0,

 //对象

 x: 0,
 y: 1,

 //对象展开
 obj1: {
  a: 1,
  b: 2
 },
 obj2: {
  c: 3,
  d: 4
 },
 p: 5,

 //对象key和value形同时
 foo: &#39;my-foo&#39;,
 bar: &#39;my-bar&#39;



 },
})
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template