uniapp單選框使用


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


免責聲明!

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



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