微信小程序参数判断

记录一下有点绕的参数 语法。

< view class= "h_recommend" wx:for= "{{adlist}}" data-id= "{{item.type==1?item.content:''}}" bindtap= "detail" >

一开始我想的是用if判断,后来才发现这个方法更简单 

data-id="{{item.type==1?item.content:''}}" 就等于

if(item.type == 1){

    id=item.content;   

}else{

    id='';

}

class添加样式

扫描二维码关注公众号,回复: 2459914 查看本文章
< view class= "{{num==1?'show':'hide'}}" >测试 </ view >

本来想在wx:if里面添加,但是不是语法不对就是无效果,

在js中设置一下num 也可以用true和false

data : {

num : 2
},
结果和上面的三元运算符一样的算法。

猜你喜欢

转载自blog.csdn.net/qq_38026437/article/details/80509091