萌新提问,英专生自学前端三件套,求求大佬看看是什么问题。
初始状态:
单击选项后状态:
js代码:
const db = wx.cloud.database();
Page({
data: {
items: [
{value: 'like', name: '热恋', checked: 'true'},
{value: 'love', name: '已婚'},
],
radioChange(e) {
console.log('radio发生change事件,携带value值为:', e.detail.value)
const items = this.data.items
for (let i = 0, len = items.length; i < len; ++i) {
items[i].checked = items[i].value === e.detail.value
}
this.setData({
items: e.detail.value
})
}
})
wxml代码:
<view class="page-section">
<view class="weui-cells weui-cells_after-title">
<radio-group name="marry" bindchange="radioChange">
<label class="weui-cell weui-check__label" wx:for="{{items}}" wx:key="{{item.value}}">
<view class="weui-cell__hd">
<radio value="{{item.value}}" checked="true" />
</view>
<view class="weui-cell__bd">{{item.name}}</view>
</label>
</radio-group>
</view>
</view>
这里的问题,修改成 items 即可。