<!-- 單選 -->
<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(",") //將數組轉化為字符串向后台傳遞
},
