美文网首页
2018-03-30 点击事件切换 三元运算符

2018-03-30 点击事件切换 三元运算符

作者: 超人又来了 | 来源:发表于2018-03-30 09:33 被阅读0次

1.点击事件切换

  month:function(e){
        var that = this
        if (that.data.month === e.target.dataset.month){
            return false
        } else {
            that.setData({
                month: e.target.dataset.month
            })
        }
    }

2.三元运算符

  class="{{ today ? 'on' : 'default' }}"
  src="../images/{{ bool ? 'weixuanzhong' : 'xuanzhong' }}.png"

3.截取字符串

<wxs module="util">
    var sub = function(val) {
        return val.substring(0, 2)
    }
    module.exports.sub = sub;
</wxs>

<view>{{util.sub(gatewayIeee.name)}}</view>

4.小程序判断空

if (array === undefined || array.length == 0) {
    // array empty or does not exist
}

相关文章

网友评论

      本文标题:2018-03-30 点击事件切换 三元运算符

      本文链接:https://www.haomeiwen.com/subject/epubcftx.html