商品多规格选择
数据格式如下
选择界面如图
渲染界面
page_config.NewSpecInfo = res.data;
var specshtml = '';
specshtml += '<h3>' + data.GoodsName + '</h3>';
specshtml += '<p class="clearfix"><label>零售价<b class="redCol" id ="specs_goods_price_' + data.Id + '" >¥</b></label>';
specshtml += '<span id="specs_goods_stock_' + data.Id + '">库存 件</span></p>';
specshtml += '<div id="newspecopt">';
if (res.data[0].SpecsKey1 != undefined && res.data[0].SpecsKey1 != null) {
specshtml += '<dl data-specs_key_id="' + res.data[0].SpecsKey1 + '" data-specs_goods_id="' + data.Id + '" class="clearfix">';
specshtml += '<dt>' + res.data[0].SpecsKeyName1 + '</dt>';
var vid = [];
$.each(res.data, function (index, item) {
if (item.SpecsKey1 == res.data[0].SpecsKey1) {
var flag = true;
$(vid).each(function (k, v) {
if (v.SpecsValue1 == item.SpecsValue1) {
flag = false;
return false;
}
});
if (flag) {
vid.push(item);
}
}
});
if (vid.length > 0) {
$(vid).each(function (index, item) {
specshtml += '<dd class="one" data-value="' + item.SpecsValue1 + '" id="' + item.SpecsValue1 + '" >' + item.SpecsValueName1 + '</dd>';
});
}
specshtml += '</dl>';
}
if (res.data[0].SpecsKey2 != undefined && res.data[0].SpecsKey2 != null) {
specshtml += '<dl data-specs_key_id="' + res.data[0].SpecsKey2 + '" data-specs_goods_id="' + data.Id + '" class="clearfix">';
specshtml += '<dt>' + res.data[0].SpecsKeyName2 + '</dt>';