转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-13/

在前面的小节里面其实对数据绑定都有所了解了,在这次给老铁在好好说下数据绑定,看下它的方方面面是如何实现的。源码:https://github.com/limingios/wxProgram.git 中的No.8

小程序的数据绑定

  1. JQuery dom 操作 $选择器
  2. 微信小程序是通过数据绑定 vue/react
  3. .js 中通过data 对象与.wxml的元素绑定{{data}} ->Mustache 表达式语法

    Mustache 是一款经典的前端模板引擎,在前后端分离的技术架构下面,前端模板引擎是一种可以被考虑的技术选型,随着重型框架(AngularJS、ReactJS、Vue)的流行,前端的模板技术已经成为了某种形式上的标配,Mustache 的价值在于其稳定和经典:
    主页:https://github.com/janl/mustache.js/
    文档:https://mustache.github.io/mustache.5.html
    Mustache 在使用的时候,会在页面上出现 {{person}} 这样的标签,载入的时候回显示出来,然后立即被替换掉,这个对于页面的呈现是不够友好的,这是我在使用的过程中遇到的一个痛点。

  4. 官方的阐述

    https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/data.html

  1. 演示绑定
    >* 数据绑定使用 Mustache 语法(双大括号)将变量包起来
    >* 关键字(需要在双引号之内)
    true:boolean 类型的 true,代表真值。
    false: boolean 类型的 false,代表假值。
    >* 可以在 {{}} 内进行简单的运算,支持的有如下几种方式:
    三元运算
    算数运算
    逻辑判断
    字符串运算

dataBind.wxml

<!dataBind.wxml-->
<view class="container" id='item={{id}}'>
{{msg}}
<!-- 控制属性(需要在双引号之内) 关键字(需要在双引号之内)-->
<checkbox checked="{{false}}"> </checkbox>
<checkbox checked="{{true}}"> </checkbox>
<checkbox checked="{{flag}}"> </checkbox>
<checkbox checked="{{unflag}}"> </checkbox>
<!-- 三目运算符-->
{{a+b==5?"是5":"不是5"}}
<!--算数运算-->
<view> {{a + b}} + {{c}} </view>
<!---字符串运算-->
<view> {{msg + hello + "test"}} </view>
<!---数字和字符串拼接-->
<view> {{a + b + "test"}} </view>
</view>

dataBind.js

//dataBind.js
//获取应用实例
const app = getApp() Page({
data: {
msg: "这是一个msg",
id: 1001,
flag: true,
unflag: false,
a: 1,
b: 4,
c: 5,
hello: "hello"
} })

「小程序JAVA实战」小程序视图之细说数据绑定(13)的更多相关文章

  1. 「小程序JAVA实战」小程序的flex布局(22)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...

  2. 「小程序JAVA实战」小程序的留言和评价功能(70)

    转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...

  3. 「小程序JAVA实战」小程序的举报功能开发(68)

    转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...

  4. 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...

  5. 「小程序JAVA实战」小程序的关注功能(65)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...

  6. 「小程序JAVA实战」小程序的视频点赞功能开发(62)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...

  7. 「小程序JAVA实战」小程序的springboot后台拦截器(61)

    转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...

  8. 「小程序JAVA实战」小程序首页视频(49)

    转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...

  9. 「小程序JAVA实战」小程序视频封面处理(48)

    转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...

  10. 「小程序JAVA实战」小程序上传短视频(46)

    转自:https://idig8.com/2018/09/14/xiaochengxujavashizhanxiaochengxushangchuanduanshipin45/ 个人信息:用户上传短视 ...

随机推荐

  1. linux命令三

    作业一:1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) [root@bogon test]# cat /etc/passwd /etc/group > /1. ...

  2. OC-通知+Block

    =================================== 一.通知(NSNotification) NSNotification 通知类,这个类中有 NSNotificationCent ...

  3. 剑指offer--35.数组中只出现一次的数字

    时间限制:1秒 空间限制:32768K 热度指数:198150 本题知识点: 数组 题目描述 一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. class ...

  4. New Concept English three (26)

    34w/m 54words No one can avoid being influenced by advertisements. Much as we may pride ourselves on ...

  5. PostgreSQL 全文检索

    PostgreSQL 8.3.1  全文检索(转) 在postgreSQL 8.3自带支持全文检索功能,在之前的版本中需要安装配置tsearch2才能使用,安转配置tsearch2就不再多说了,主要介 ...

  6. File I/O的总结

    1读写字符文件 BufferedReader br=new BufferedReader(new FileReader("文件路径")); BufferedWriter bw=ne ...

  7. windows获取屏幕显示比例 读取注册表法

    static int GetDesktopScale() { ; HINSTANCE hUser32 = LoadLibrary(L"user32.dll"); if (hUser ...

  8. 本站上线KMS服务~一句命令激活windows和office

    服务器地址:kms.luody.info 更新: 脚本维护更新:2016-09-29 服务端版本:vlmcsd-1108-2017-01-19-Hotbird64 服务作用:在线激活windows和o ...

  9. haroopad 语法高亮问题

    <!DOCTYPE html> Untitled.html div.oembedall-githubrepos{border:1px solid #DDD;border-radius:4p ...

  10. Python之json文件

    { "people":[ { "firstName": "Brett", "lastName":"McLaug ...