SKU table example generated using jQuery and layui
Add-ons

Plugin Description: An SKU table example generated using jQuery and layui, with fully commented code.
Last Updated: 2020-03-26 23:23:07
Changelog:When adding specifications for the first time, the sku-active class is added by default. This eliminates the need to reselect a specification when adding its values, improving the user experience.
Last Updated: 2020-03-25 23:45:57
The tricky part lies in the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Initialize the result with the first arrayvar result = arr[0];// Iterate through the two-dimensional array starting from index 1for (var i = 1; i < arr.length; i++) { // Use a temporary variable instead of the result array length (this prevents the following loop from entering an infinite loop) var size = result.length; // Determine the number of iterations based on the result array length. Each element in this array must be combined with the next array. for (var j = 0; j < size; j++) { // Iterate through the array to be combined for (var k = 0; k < arr[i].length; k++) { // Add the combined string to the last element of the result array // Index 0 is used here because it is no longer needed after its combinations are completed. We will remove this element below. result.push(result[0] + "," + arr[i][k]); // $('#tbody').append('<tr><td>'+result[0]+'</td><td>'+arr[i][k]+'</td><td><input/> </td></tr>') } // Once the combinations for the first element are complete, remove that first element result.shift(); }} |
评论