Home > WeChat Applet > Mini Program Development > Implementation code for data binding and simple logical operations in WeChat applet

Implementation code for data binding and simple logical operations in WeChat applet

不言
Release: 2018-09-06 10:40:41
Original
2539 people have browsed it

The content of this article is about the implementation code of data binding and simple logical operations in WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. .

1. Simple usage:

Page({
  data: {
    message: '张三'
  }
})

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var content1={
         date: "2020年 10月 8日 ",  
         title:"时间群" ,
         nameData:{
              name1:"张三李四",
              name2:"人五人六",
         },
         fade:true/false 
      }
      this.setData(content);
  },
Copy after login

2. Data binding uses Mustache syntax (double curly brackets) to wrap variables to obtain:

<view> {{ date}} </view>
<view> {{ title}} </view>
<view> {{ nameData.name1}} </view>
<view> {{ nameData.name2}} </view>//层级用点取值
<image wx:if="{{fade}}"  class="image" src=""></image>//隐藏/显示
Copy after login

3. Can be found in {{ }} Perform simple operations in:

三元运算符
<view hidden="{{flag ? true : false}}"> Hidden </view>
Copy after login

4. Calculation:

<view> {{a + b}} + {{c}} + d </view>
Copy after login
Page({
  data: {
    a: 1,
    b: 2,
    c: 3
  }
})
输出结果:3 + 3 + d
Copy after login

5. Logical judgment:

<view wx:if="{{length > 5}}"> </view>
Copy after login

6. It can also be combined directly in Mustache to form New object or array:

<view wx:for="{{[zero, 1, 2, 3, 4]}}"> {{item}} </view>
Copy after login
Page({
  data: {
    zero: 0
  }
})
输出结果:组合成数组[0, 1, 2, 3, 4]。
Copy after login

7. Object:

<template is="objectCombine" data="{{for: a, bar: b}}"></template>
Copy after login
Page({
  data: {
    a: 1,
    b: 2
  }
})
最终组合成的对象是 {for: 1, bar: 2}
Copy after login

Related recommendations:

jquery form form to obtain content and bind data_javascript skills

Example analysis of two-way binding application of data in AngularJS framework_AngularJS

The above is the detailed content of Implementation code for data binding and simple logical operations in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

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