如何循环html数据制作[{},{}]格式,向后台传递多个数据
var allobject=[ ];
$('.P_center').each(function(){
//获取对象所需要的值
var courseId = $(this).data('id');
var buyNum = $(this).data('quantity');
var buyPrice = $('.P_su').text();
//将获取好的值保存到对象中
var object = {
"courseId":courseId,
"buyNum":buyNum,
"buyPrice":buyPrice
}
//将对象保存到数组中
allobject.push(object );
});
//将数组转换为json类型的字符串
var allobjectJSON = JSON.stringify(allobject);
//获取对象所需要的值
var courseId = $(this).data('id');
var buyNum = $(this).data('quantity');
var buyPrice = $('.P_su').text();
//将获取好的值保存到对象中
var object = {
"courseId":courseId,
"buyNum":buyNum,
"buyPrice":buyPrice
}
//将对象保存到数组中
allobject.push(object );
});
//将数组转换为json类型的字符串
var allobjectJSON = JSON.stringify(allobject);