<!-- 单选 -->
<view v-if="itemtwo.temp_question_type==0">
<radio-group :name="itemtwo.id" @change="chkdanxuan">
<block v-for="itemthree,indexthree in itemtwo.temp_question_option.option" :key="itemthree.code">
<radio :value="itemtwo.id+‘ ‘+itemthree.code" :name="itemthree.code" /> {{itemthree.code}} {{itemthree.value}}</br>
</block>
</radio-group>
</view>
函数
// 单选题
chkdanxuan: function(e,id) {
_self.danxuanxz = e.detail.value; //定义cls获取复选框的数组值
//字符串转数组 取得 行id 及选择内容
let strdx=_self.danxuanxz;
let strarry=strdx.split(‘ ‘);
//拿到索引
let idx = strarry[0];
//拿到记录的id
let ids = strarry[0];
//判断选择的这个记录是否之前就选择过了
var index0 = _self.answer.findIndex(item => {
if (item.id == strarry[0]) {
// 查询到后删除
_self.answer.splice(index0, 1);
return true
}
})
// var index0= _self.answer.findIndex(function(obj){
// return obj.id === strarry[0];
// })
// 重新增加数据
_self.answer.push({
‘id‘: strarry[0],
‘choice_code‘: [strarry[1]]
});
console.log(e.detail);
// console.log(strarry);
console.log(_self.answer);
// _self.qx=_self.qx.join(",") //将数组转化为字符串向后台传递
},