0
我有一個表格收集僱員生產數據,以下是代碼:Javascript對象結構
$(document).on('click','input#Apply.btn.btn-success',function(e){
var TableData;
TableData = storeTblValues();
var TableData1 = [];
$.each(TableData,function(index,value){
if(value.quantity && value.quantity >0 && value.quantity < 65535){
TableData1[index]={
"employee_id" : value.employee_id
, "operation_id" : value.operation_id
, "quantity" : value.quantity
}
}
});
// retrieving employee_id to fetch date data from date input
$.each(TableData1,function(index,value){
employee_idj = value.employee_id;
});
$('#cboxClose').click();
var datee = dateConvToMySqlDate($('input#dateOfProduction_'+employee_idj+'.dateOfProduction_.hasDatepicker').val());
if(!datee){alert(dateMessager);e.preventPropagation();return false;}
var noOfRecords = TableData1.length;
for(i=0;i<noOfRecords;i++)
{TableData1[i]['production_date'] = datee;}
var TableData1 = $.toJSON(TableData1);
alert(JSON.stringify(TableData1));
var qurl = '<?php echo base_url();?>production_entry/submitData';
$.ajax({
url: qurl,
type: "POST",
data:"pTableData=" + TableData1,
success: function(data){
var data = $.parseJSON(data);
if(data.status == 'error')
{
alert(data.errorMessage);
}else{
alert(noOfRecords+' records sent and '+' '+data.successMessage);
$('#tr_'+employee_idj).fadeOut();
}
}
});
function storeTblValues()
{
var TableData = new Array();
$('#searchOperationTable tr').each(function(row, tr){
var x = parseInt($(tr).find("input.quantity").val());
if(x){
TableData[row]={
"employee_id" : parseInt($(tr).find("input.hiddenemployeeId").val())
, "operation_id" : parseInt($(tr).find('td:eq(0)').text())
, "quantity" : parseInt($(tr).find("input.quantity").val())
}
}
});
TableData.shift();
return TableData;
}
});
當有人進入等於0的數量值錯誤,則該TableData1對象變爲
[ null,{"employee_id" : 3816,"operation_id":3,"quantity":10}]
並且腳本停止工作。我想消除這個null。該怎麼辦?