我试图将一个数组从复选框传递到jquery对话框,但是仅在数组中有2时才输出第二个值。当我提交数组时,在console.log中,它显示如下,您可以看到它包含2个值,但是对话框仅显示第二个值:
Array(10) [ "14", "Standard", "New Box Intake", "DEMO", "DEMO", "22 London Road Charles House London W12 3RT ", "Demo User", "DEMOBOX0014", "N/A", "14/01/2033" ]
Array(10) [ "16", "Standard", "New Box Intake", "DEMO", "DEMO", "22 London Road Charles House London W12 3RT ", "Demo User", "DEMOBOX0016", "N/A", "14/01/2033" ]
如果有人可以检查我的代码并帮助我理解我的错误,我将不胜感激,因为我对jquery还是很陌生。非常感谢。
对话框代码
$(function() {
//$(".defaultBtn").prop('disabled',true);
$('#rack').dialog({
autoOpen: false,
title: 'New Intake Slot Assingment',
height: 520,
width: '50%',
modal: true,
resizable: false,
position: {
my: 'top',
at: 'top+35'
},
open: function(event, ui) {
$('#rack').css('overflow', 'hidden'); //this line does the actual hiding
$(info).each(function(index, data) { // should open an array here
console.log(data);
});
},
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "blind",
duration: 1500
},
buttons: [{
text: "Submit",
"class": 'defaultBtn',
click: function(e) {
e.preventDefault();
var data = $('#rack').serialize();
console.log(data);
$.ajax({
type: 'POST',
url: '/lsorg/admin/niajax.php',
data: data,
async: false,
beforeSend: function() {
$(".text").show().html('Processing your request...');
},
success: function(data) {
if (data.trim() == 'All fields must be completed') {
$(".text").html('ERROR: You must complete all fields for the slot assignment.').css({
"color": "red",
"font-size": "13px",
"margin-left": "21px"
});
return false;
} else {
$.get('/lsorg/admin/refreshActions.php?count=' + 'Actions', function(data) {
//console.log(data);
$(".actions").text(data);
});
$.get('/lsorg/admin/refreshActions.php?count=' + 'New Box Intake', function(data) {
//console.log(data);
$(".ni").text(data);
});
$("#rack").dialog("close");
activity = 'New box Intake Assignment';
showModelActionSuccess(data);
$(".text").empty();
$("#rack").trigger("reset");
tableni.ajax.reload(null, false);
return false;
}
},
error: function(xhr) {
$(".text").fadeIn(4000).html('Error occured.please try again').fadeOut(4000);
},
complete: function() {},
})
}
}, {
text: "Cancel",
"class": 'defaultBtnClose',
click: function() {
$(this).dialog("close");
$("#rack").trigger("reset");
$(".text").empty();
}
}, ],
close: function() {
$("#rack").trigger("reset");
$(".text").empty();
$(".chosen-select").attr("data-placeholder", "Select a box size").val('').trigger('chosen:updated');
}
});
});
jquery代码
$(function() {
$(document).on('click', '.rowChk', function() {
currentRows = $(this).closest("tr");
rackid = currentRows.find("td:eq(0)").html();
rackservice = currentRows.find("td:eq(2)").html();
rackactivity = currentRows.find("td:eq(3)").html();
rackdept = currentRows.find("td:eq(4)").html();
rackcompany = currentRows.find("td:eq(5)").html();
rackaddress = currentRows.find("td:eq(6)").html();
rackuser = currentRows.find("td:eq(7)").html();
rackitem = currentRows.find("td:eq(8)").html();
//rackboxsize = currentRows.find("td:eq(8)").html();
rackddate = currentRows.find("td:eq(9)").html();
rackdate = currentRows.find("td:eq(10)").html();
info = [];
info[0] = rackid;
info[1] = rackservice;
info[2] = rackactivity;
info[3] = rackdept;
info[4] = rackcompany;
info[5] = rackaddress;
info[6] = rackuser;
info[7] = rackitem;
info[8] = rackddate;
info[9] = rackdate;
});
});
将数组值传递给对话框
$(document).on('click', '#rowClk', function() {
$("#rack").dialog("open");
$("#rack_id").val(info[0]);
$("#rack_service").val(info[1]);
$("#rack_activity").val(info[2]);
$("#rack_dept").val(info[3]);
$("#rack_company").val(info[4]);
$("#rack_address").val(info[5]);
$("#rack_user").val(info[6]);
$("#rack_item").val(info[7]);
$("#rack_datetimepicker").val(info[8]);
$("#rack_ddatetimepicker").val(info[9]);
console.dir(info);
});