Showing
1 changed file
with
13 additions
and
2 deletions
@@ -29,10 +29,21 @@ const _procProductImg = (product, gender, yhChannel) => { | @@ -29,10 +29,21 @@ const _procProductImg = (product, gender, yhChannel) => { | ||
29 | const _sortListByField = (list, key, desc) => { | 29 | const _sortListByField = (list, key, desc) => { |
30 | list = _.toArray(list); | 30 | list = _.toArray(list); |
31 | list = list.sort((a, b) => { | 31 | list = list.sort((a, b) => { |
32 | + let matchNumber = /([\d]+)/g; | ||
33 | + | ||
34 | + // 有键,使用键的值排序 | ||
32 | if (a[key] && b[key]) { | 35 | if (a[key] && b[key]) { |
33 | - return (desc ? a[key] > b[key] : a[key] < b[key]) ? -1 : 1; | 36 | + let numA = +(_.toArray(a[key].match(matchNumber))[0] || 0); // 取第一个出现的数字排序,如果不存在,取0 |
37 | + let numB = +(_.toArray(b[key].match(matchNumber))[0] || 0); | ||
38 | + | ||
39 | + return (desc ? numA > numB : numA < numB) ? -1 : 1; | ||
34 | } | 40 | } |
35 | - return (desc ? a > b : a < b) ? -1 : 1; | 41 | + |
42 | + // 无键, 使用本身 | ||
43 | + let numA = +(_.toArray(a.match(matchNumber))[0] || 0); | ||
44 | + let numB = +(_.toArray(b.match(matchNumber))[0] || 0); | ||
45 | + | ||
46 | + return numA < numB ? -1 : 1; | ||
36 | }); | 47 | }); |
37 | return list; | 48 | return list; |
38 | }; | 49 | }; |
-
Please register or login to post a comment