小程序的基本原生js使用

1.点击事件

       <a data-current="{{setting.current}}" bindtap="clickcurrent" style="color:{{currentSelect.key == 'current'?mainColor:oldcolor}};">
           <text>本期试用</text>
           <text class="activeline" style="background-color:{{currentSelect.key == 'current'?mainColor:whiteColor}};"></text>
       </a>
      bindtap="clickcurrent" 

2.style的使用

style="color:{{currentSelect.key == 'current'?mainColor:oldcolor}};"

3.传值

data-current="{{setting.current}}"

如何获取

传过来event ,然后写event.currentTarget.dataset.current

4.wx:if的动态使用

wx:if="{{currentSelect.key == 'current'}}"

5.循环的使用,默认item和index.

 <view class="fishqcTrycurrentProduct" wx:for="{{tryarray}}" wx:if="{{havacurrentdata}}" wx:key="{{item.id}}">

怎么样去修改变量名?

<view wx:for="{{array}}" wx:for-index="idx" wx:for-item="itemName">
  {{idx}}: {{itemName.message}}
</view>

6.设置数据

     var that = this
        that.setData({
            currentSelect: event.currentTarget.dataset.current
        })
原文地址:https://www.cnblogs.com/antyhouse/p/9855530.html