قبل أن أقدم النص الرئيسي ، سأضيف بعض المعرفة إليك:
خوارزمية منتجات JS Dicsian
توليد منتج ديكارت من الكائن أو المصفوفة المحددة
// cartesian combiner combiner combint function descartes (list) {// parent index prevent ؛ count count count var point = {} ؛ var result = [] ؛ var pindex = null ؛ var tempcount = 0 ؛ var temp = [] {'parent': pindex ، 'count': 0} pindex = index ؛}} // إرجاع بنية بيانات أحادية الأبعاد مباشرة if (pindex == null) {return list ؛} // generation dynamic generation of cartesian ching (exter] {for (var index in list) {tempcount = point [index] نتائج صفيف النتيجة. push (temp) ؛ temp = [] ؛ // تحقق من مشكلة قيمة المؤشر القصوى بينما (صواب) {if (point [index] ['count']+1> = list [index] .length) {point [index] pindex ؛} آخر {point [index] ['count'] ++ ؛ break ؛}}}}}}حسنًا ، خوارزمية الجيل الديكارت JS هي فقط وضع الأساس للنص التالي. لن أقول الكثير ، لذلك سأعود إلى هذه النقطة.
1. وصف المتطلبات
وظيفة إصدار المنتج لمواقع التجارة الإلكترونية ، على غرار صفحة تفاصيل المنتج في jd.com ، كما هو موضح في الشكل أدناه ، كيف يتم إنشاء هذه الوظيفة القابلة للاختيار في الخلفية؟ في الواقع ، فإن iPhone 6 الذي تراه ليس مجرد منتج عند إصداره ، ولكن الكثير ، لأن سعر كل iPhone 6 المحدد مختلف ، لذلك عند نشر المنتج ، يتم تحديد هذه العناصر الاختيارية من مجموعة من السمات وقيم السمات. المشكلة هي أن عدد السمات المحددة أثناء النشر مختلفة ، وقيم السمات مختلفة أيضًا. ثم يتم الجمع بين عدد المنتجات التي تم إنشاؤها بناءً على السمات وقيم السمات.
2. قم بتحميل الكود مباشرة
<script>/*** نوع سمة المنتج*عدد السمات غير مؤكد*/var spec = function (specname ، specitems) {this.specname = specname ؛ // اسم السمة اسم this.specitems = specitems ؛ // القيمة العددية عبارة [{specname: "السعة" ، specitems: ['16g' ، '64g' ، '128g']} ، {specname: 'color' ، specitems: ['top gold' ، 'silver' ، 'black' ، 'pink']} ، {specname: network '، specitems: Current) {if (index <selectsspec.length - 1) {var specitem = selectspec [index] ؛ var keya = specitem.specname ؛ var under = specitem.specitems ؛ if (items.length == 0) {run (index+1 ، current) ؛ {} ؛ newmap = $ .Extend (newmap ، current) ؛ newmap [keya] = العناصر [i] ؛ تشغيل (index + 1 ، newmap) ؛}} آخر إذا (index == selectspec.length - 1) {var specitem = selectspec [index] specitem.specitems ؛ if (items.length == 0) {result.push (current) ؛} for (var i = 0 ؛ i <items.length ؛ i ++) {if (! item [i]) متابعة ؛ var newmap = {} ؛ newmap = $. العناصر [i] ؛ result.push (newmap) ؛}}} combine (0 ، {}) ؛ console.info (result) ؛/** مجتمعة في مجموعة المنتج * [كائن {cumper = "16g" ، color = "tulujin" ، network = "interview"} ، * object {cumper = "16g" Object {cumper = "16g" ، color = "大天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天天 � object {cumper =" 16g "، color =" black "، network =" telecom "} ، * object {cumper =" 16g "، color = network = "telecom"} ، * object {cumper = "64g" ، color = "telecom"} ، * object {cumper = "64g" ، color = "telecom} ، * object {cumper =" 64g "، color =" reghury gold "، network = CATER = "64G" ، color = "Silver" ، network = "mobile"} ، * object {cumper = "64g" ، color = "silver" ، network = "telecom"} ، * object {cute = "64g" ، color = "black" ، network = "unicom"} ، color = "black" ، network = "telecom"} ، * object {cute = "64g" ، color = "black" ، network = "telexom"} ، * object {cute = "64g" ، color = "pink" ، network = "unicom} ، * object {cumper =" 64g "، color = network = "telecom"} ، * object {cumper = "128g" ، color = "telecom"} ، * object {cumper = "128g" ، color = "telecom"} ، * object {cumper = "128g" ، color = "128g" ، comple = "128g" ، comple "، comple" ، comple "، comple" ، comple "، cother" ، cother = network = "unicom"} ، * object {cute = "128g" ، color = "silver" ، network = "mobile"} ، * object {cumper = "128g" ، color = "silver" ، network = "telecom"} ، * {comple = "mobile =" 128g "، color =" black "، network =" unicom} ، * Object {cumper = "128g" ، color = "black" ، network = "telecom} ، * object {cute =" 128g "، color =" pink "، network =" unicom "} ، * object {cumper =" 128g "، color =" pink "، network = Network = "Telecommonications"}]*/</script>ما ورد أعلاه هو محتوى المنتج الذي يصدره المنتج الديكارتي بناءً على تطبيق JS الذي تم تقديمه إليك. آمل أن يكون ذلك مفيدًا لك. في الوقت نفسه ، أنا ممتن جدًا لك على دعمك لموقع Wulin Network. أعتقد أننا سنفعل ما هو أفضل!