Last active
March 23, 2017 07:27
-
-
Save youzipi/5101d414abf83eed2535b2dfe16442b3 to your computer and use it in GitHub Desktop.
lodash-bala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var areas = _.chain(nodes) | |
.filter(function (node) { | |
switch (node.id[0]) { | |
case 'p': // 省 是全选状态 | |
return isFullCheck(node); | |
case 'c': // 市 是全选状态 and 上级(省)是半选 | |
return isFullCheck(node) | |
&& !isFullCheck(node.getParentNode()); | |
case 'd': // 区县 是全选状态 and 上级(市)是半选 | |
return !isFullCheck(node.getParentNode()); | |
} | |
}) | |
.map(function (node) { | |
return _.zipObject(['level', 'id'], [levelArea[node.level], node.id.substring(1)]); | |
// ex: {level:'p',id:'1100000000'} | |
}) | |
.groupBy('level') | |
.value(); | |
var getIds = fp.map('id'); // 可以返回 [],不需要defaultIds | |
// var defaultIds = function (ids) { | |
// return getIds(ids) || [] | |
// }; | |
var provinceIds = getIds(areas['p']); | |
var cityIds = getIds(areas['c']); | |
var districtIds = getIds(areas['d']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 添加套装:计算套装中商品的最低总价 和最高总价 | |
var calPrice = fp.reduce( | |
function (sum, a) { | |
return sum + parseInt( | |
_.multiply($(a).text(), $(a).parents('td').next().text()) | |
) | |
}, 0); | |
var minSumPrice = calPrice($('.minPrice')); | |
var maxSumPrice = calPrice($('.maxPrice')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fp.flow( | |
fp.replace(/[\[\]]/g, ''), | |
fp.split(','), | |
fp.map(_.trim) | |
)('[a,b,c, d]') | |
// output: ['a','b','c','d'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getIds = fp.map('id'); // 可以返回 [],不需要defaultIds | |
// var defaultIds = function (ids) { | |
// return getIds(ids) || [] | |
// }; | |
var provinceIds = getIds(areas['p']); | |
var cityIds = getIds(areas['c']); | |
var districtIds = getIds(areas['d']); | |
var calPrice = fp.reduce( | |
function (sum, a) { | |
return sum + parseInt( | |
_.multiply($(a).text(), $(a).parents('td').next().text()) | |
) | |
}, 0); | |
var minSumPrice = calPrice($('.minPrice')); | |
var maxSumPrice = calPrice($('.maxPrice')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment