bootstrapSwitch開關組件在模態框動態加載問題(動態初始化開關狀態)


 
        
//打開車輛操作模態框 加載開關數據
function control(id) {
    //通過uniqueId 獲取行數據
    var rows = $('#vehicleInfoTab').bootstrapTable('getRowByUniqueId', id);

    $("#id").val(rows.id);
    $("#gpsNo").val(rows.gpsNo);
    //展示車輛操作模態框
    $('#controlModal').modal('show');
    $('#controlModal').on('shown.bs.modal', function () {
        //移動報警的開關switch
        $("#moveSwitch").bootstrapSwitch({
            onText: "開",      // 設置ON文本  
            offText: "關",    // 設置OFF文本  
            onColor: "success",// 設置ON文本顏色     (info/success/warning/danger/primary)  
            offColor: "danger",  // 設置OFF文本顏色        (info/success/warning/danger/primary)  
            size: "small",    // 設置控件大小,從小到大  (mini/small/normal/large)  
            handleWidth: "35",//設置控件寬度
            // 當開關狀態改變時觸發  
            onSwitchChange: function (event, state) {
                if (state == true) {
                    //開  <!--7:移位報警開;
                    var sCmdV = 7;
                    var gpsNo = $("#gpsNo").val();
                    $.post("/system/vehicle/sendCmd?gpsNo=" + gpsNo + "&cmd=" + sCmdV, function (data) {
                        if (data) {
                            // toastr.success("發送成功");
                            $('#vehicleInfoTab').bootstrapTable('refresh');
                        } else {
                            toastr.error("發送失敗");
                        }
                    });
                } else {
                    //關  8:移位報警關-->
                    var sCmdV = 8;
                    var gpsNo = $("#gpsNo").val();
                    $.post("/system/vehicle/sendCmd?gpsNo=" + gpsNo + "&cmd=" + sCmdV, function (data) {
                        if (data) {
                            // toastr.success("發送成功");
                            $('#vehicleInfoTab').bootstrapTable('refresh');
                        } else {
                            toastr.error("發送失敗");
                        }
                    });
                }
            }
        }).bootstrapSwitch('state',rows.move);//必須放在最后才能初始化值
 });
}

//效果圖

 

 


免責聲明!

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



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