Javascript 避免使用lodash导入整个库并避免uu导致整个库加载
我需要从lodash库导入u,该库将从lodash导入所有类。是否有任何解决方案可以通过仅导入所需的库来避免导入此“u”Javascript 避免使用lodash导入整个库并避免uu导致整个库加载,javascript,ecmascript-6,lodash,Javascript,Ecmascript 6,Lodash,我需要从lodash库导入u,该库将从lodash导入所有类。是否有任何解决方案可以通过仅导入所需的库来避免导入此“u” import _ from 'lodash'; import './style.css'; import _ from 'lodash'; import {pick,head,uniqBy,map,partialRight as pr,omit} from 'lodash'; const baseProps = ['dc', 'effDate', 'expDate'];
import _ from 'lodash';
import './style.css';
import _ from 'lodash';
import
{pick,head,uniqBy,map,partialRight as pr,omit} from 'lodash';
const baseProps = ['dc', 'effDate', 'expDate'];
const data = [{"dc":1,"effDate":"1/2/2019","expDate":"1/2/2019","rate":1,"minCharge":2},{"dc":1,"effDate":"1/2/2019","expDate":"1/2/2019","rate":2,"minCharge":6},{"dc":1,"effDate":"1/2/2019","expDate":"1/2/2019","rate":4,"minCharge":7}];
const result =_(data).groupBy('effDate')
.map(g => ({
...pick(head(g), baseProps),
rateCharge: uniqBy(map(g, pr(omit, baseProps)), 'rate')
})).value();
console.log(result)
Actual & Expected Output
[
{
"dc": 1,
"effDate": "1/2/2019",
"expDate": "1/2/2019",
"rateCharge": [
{
"rate": 1,
"minCharge": 2
},
{
"rate": 2,
"minCharge": 6
},
{
"rate": 4,
"minCharge": 7
}
]
}
];
我的组织编码标准不允许从“loadash”导入“\u1”,因为它将导入整个库。由于我在Typescritp Angular中工作,我无法找到替代解决方案。只需删除即可
从“lodash”导入;
并更改此行:
import{pick,head,uniqBy,map,partialas pr,omit}来自'lodash';
为此:
从'lodash'导入{pick,head,uniqBy,map,partialas pr,omit,groupBy};
同时更改此行:
const result=(数据).groupBy('effDate')
为此:
const result=data.groupBy('effDate')
它应该可以工作。这不起作用?从“lodash”导入{pick,…};可能重复