1、把多个同名(name="country")数组封装成countrys:[{"countryId":"10086","countryName":"中国"}]
形式传给后台;
2、$.post时,既传输表单数据,又传输封装好的对象。
<div class="col-md-6">
<input type="checkbox" class="checkName" value='"countryId":"{{countryList.id}}","countryName":"{{countryList.regionName}}"' {{region_selected}}>{{countryList.regionName}}</input>
</div>
submitHandler: function(form) {
// console.log(form1.serializeArray());
// // return false;
var countryChecked = new Array();
var list = {};
var countrys = new Array();
// allCountry = $('#model_add_form .checkName');
allCountry = document.getElementById('model_add_form').getElementsByClassName('checkName');
for (k in allCountry){
if(allCountry[k].checked)
countryChecked.push(allCountry[k].value)
}
for (let i in countryChecked){
var temp = JSON.parse("{"+countryChecked[i]+"}");
countrys.push(temp);
}
var submitData = form1.serializeArray();
submitData.push({name:'countrys',value:countrys})
error1.hide();
App.blockUI({
target: '#model_add_form',
overlayColor: 'none',
cenrerY: true
});
$.post('/ModelAdd',submitData,function(data){
App.unblockUI('#model_add_form');
$("#ajax-modal").modal('hide');
ModelManager.refresh();
}).error(function (err) {
App.unblockUI('#model_add_form');
swal({
title: i18n.t('swal_title_error'),
text: i18n.t(err.responseText),
confirmButtonText: '<i class="fa fa-check"></i> Ok',
confirmButtonClass: 'btn btn-circle btn-success',
buttonsStyling: false
}).done();
})
}
打印出json格式:
console.log(JSON.stringify(countrys));