js方法是这样的:
//保存提货券JSON数据到隐藏字段 saveVoucherListInfoToHiddenFiled: function () { //保存绑定商品信息 var voucherLines = $("#tbVouchersBindCommodityList .cClz"); var voucherModels = []; for (var i = 0; i < voucherLines.length; i++) { var $voucher = $(voucherLines[i]); var model = $voucher.data("voucher"); model.BindCommodities = $voucher.data("bindcommodities"); ////设置提货券的类型 //model.BindType = model.BindCommodities.length ? model.BindCommodities[0].BindType : "COMMODITY"; voucherModels.push(model); } $("#" + addVoucherModule.data.voucherListID).val(JSON.stringify(voucherModels)); //绑定促销信息 var voucherPromotionLines = $("#tbVouchersBindCommodityList .pClz"); var voucherPromotionModels = []; for (var i = 0; i < voucherPromotionLines.length; i++) { var $voucherPromotion = $(voucherPromotionLines[i]); var modelPromotion = $voucherPromotion.data("voucher"); modelPromotion.BindCommodities = $voucherPromotion.data("bindcommodities"); voucherPromotionModels.push(modelPromotion); } $("#" + addVoucherModule.data.voucherPromotionListID).val(JSON.stringify(voucherPromotionModels)); },
结果在
var modelPromotion = $voucherPromotion.data("voucher");取到的值总是有一条与上一条一样的记录,最后将第二个i改成j才完事儿。。。。回头好好总结下