js方法是這樣的:sql
//保存提貨券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)); },
結果在blog
var modelPromotion = $voucherPromotion.data("voucher");取到的值老是有一條與上一條同樣的記錄,最後將第二個i改爲j才完事兒。。。。回頭好好總結下