微信小程序 三元運算 checked


預期效果:

根據用戶性別,顯示radio group,並將相應radio checked

 

代碼如下:

  <view class="form-line">
    <view wx:if="{{userInfo.gender == '1' }}">性別:</view>
    <radio-group>
    <radio value="0" checked="{{ userInfo.gender == '0' ?'true':''}}">未知</radio>
    <radio value="1" checked="{{ userInfo.gender == '1' ? 'true' : ''}}">男</radio>
    <radio value="2" checked="{{ userInfo.gender == '2' ?'true':''}}">女</radio>   
    </radio-group>
  </view>

 

之前寫 true false,但出不來效果

<radio value="1" checked="{{ userInfo.gender == '1' ? 'true' : 'false'}}">男</radio>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM