因此,下面注释掉的代码正在lodash中工作,只是想将其转换为es6以使其更简单,更清晰,所以它的抛出错误是未定义的。这里有什么帮助吗?
main.js
body {
position: absolute;
z-index: 0;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
margin: 0;
padding: 0;
min-width: 100px;
min-height: 100vh;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.map-overlay {
flex-flow: row nowrap;
justify-content: flex-start;
width: 100vw;
height: 30vh;
bottom: 0;
left: 0;
margin: 0;
overflow-x: scroll;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: -ms-autohiding-scrollbar;
display: flex;
position: fixed;
background-color: rgba(255, 150, 150, 0.3);
font: 'Abel', 'Helvetica Neue', Arial, Helvetica, sans-serif;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
color: #8e3433;
}
.scroll {
overflow: auto;
}
.column {
flex-direction: column;
}
.row,
.column,
.flex {
display: flex;
flex-wrap: wrap;
}
div {
display: block;
}
html,
body,
#q-app {
width: 100%;
direction: ltr;
}
.mycard {
flex: 1 1 auto;
min-width: 47vw;
margin: 3px 0 9px 2vw;
justify-content: flex-end;
border-radius: 2px;
display: flex;
}
findErr方法
<script src="https://unpkg.com/vue@2.6.10/dist/vue.min.js"></script>
<link href="https://unpkg.com/quasar-extras@2.0.9/material-icons/material-icons.css" rel="stylesheet"/>
<link href="https://cdn.jsdelivr.net/npm/quasar@^1.0.0-beta.0/dist/quasar.min.css" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/quasar@^1.0.0-beta.0/dist/quasar.umd.min.js"></script>
<div id="q-app"></div>
预期产量
由于 const rejectMessagerrors = [45,67,87];
const drug = [{
"isBrand": true,
"drugName": "Lipitor",
"specialtyPrice": {}
},
{
"isBrand": false,
"drugName": "Atorvastatin Calcium",
"drugStrength": "80mg",
"drugForm": "Tablet",
"mailPrice": {
"totalQuantity": 90,
"rejectMessage": [{
"settlementCode": "45",
"settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"
}]
},
"retailPrice": {
"totalQuantity": 30,
"rejectMessage": [{
"settlementCode": "99",
"settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"
}]
},
"specialtyPrice": {}
}
];
function priceFilterHandler(drug) {
// const pricePath = ['mailPrice.rejectMessage', 'retailPrice.rejectMessage'];
//
// _.forEach(pricePath, function (path) {
// const rejectMsg = _.get(drug, path);
// const hasCode = rejectMsg && rejectMsg.find(i => !!~rejectMessagerrors.indexOf(+i.settlementCode));
// hasCode && delete drug[path.split('.').shift()];
// });
const retailHasCode = findErrCode(item.retailPrice.rejectMessage);
const mailHasCode = findErrCode(item.mailPrice.rejectMessage);
if (retailHasCode) {
delete item.retailPrice;
}
if (mailHasCode) {
delete item.mailPrice;
}
return item;
}
const filteredPrices = _.map(drug, priceFilterHandler);
中包含了结清代码45,因此价格应与let findErrCode = data => {
data.some(i => rejectMessagerrors.includes(+i.settlementCode));
}
列表元素相匹配
mailPrice
答案 0 :(得分:1)
这是您在代码中遇到的一些问题
findError
函数没有返回值mailPrice or retailPrice
的地方没有item.mailPrice.rejetcMessage
const rejectMessagerrors = [45, 67, 87];
const drug = [{"isBrand": true,"drugName": "Lipitor","specialtyPrice": {}},{"isBrand": false,"drugName": "Atorvastatin Calcium","drugStrength": "80mg","drugForm": "Tablet","mailPrice": {"totalQuantity": 90,"rejectMessage": [{"settlementCode": "45","settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"}]},"retailPrice": {"totalQuantity": 30,"rejectMessage": [{"settlementCode": "99","settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"}]},"specialtyPrice": {}}];
let findErrCode = data => data && data.some(i => rejectMessagerrors.includes(+i.settlementCode));
let op = drug.map(item=> {
const retailHasCode = findErrCode(item.retailPrice && item.retailPrice.rejectMessage);
const mailHasCode = findErrCode(item.mailPrice && item.mailPrice.rejectMessage);
if (retailHasCode) {
delete item.retailPrice;
}
if (mailHasCode) {
delete item.mailPrice;
}
return item;
})
console.log(op)