我将JSON对象oAtt
声明为var oAtt = MessageStore.message().attachments();
MessageStore.message()
在此处可用的代码中声明:https://github.com/RainLoop/rainloop-webmail/blob/master/dev/Model/Message.js
当我将其输出到控制台时,oArr
作为[object Object],[object Object]
出现。 stringify
之后为:
var oAtt = [
{"sModelName":"AttachmentModel","disposables":[],"mimeType":"application/pdf","fileName":"sample.pdf","fileNameExt":"pdf","fileType":"pdf","description":null,"estimatedSize":19333,"friendlySize":"19KB","isInline":false,"isLinked":false,"isThumbnail":false,"cid":"","cidWithOutTags":"","contentLocation":"","download":"zyfTZvzczVW6cqlcsIrm3ycmY5soz3DzK5sZhjnSOwaW0wnwGwHtqBvPeo8nVpiWD4yKVIPvAPauJHZufHGRG0Eb4MRmBpkGlvsDGP-gz3CnVp4GorN_xXCI0Gkd2I93IySKMy5iXRt-wML9wxLwTZcrOMLyPp-Kr6b0GlzlHuvk3RqEXRqSlCQTX5piRO6AaRYeMKeq8PSJcId1grMYzFpCnjVSoW_Zj7yTGAsy-D_mzFoCmBdksCweEqPdGhFYFkukblXzaZiTSNGTj1xYOvMIN4XXUZtU0EAPoQ9EFxfPWY_-1Siyge0Gks2zbGs3myxXJg..","folder":"INBOX","uid":"22","mimeIndex":"2","framed":false},
{"sModelName":"AttachmentModel","disposables":[],"mimeType":"image/jpeg","fileName":"test4.jpg","fileNameExt":"jpg","fileType":"image","description":null,"estimatedSize":26326,"friendlySize":"26KB","isInline":false,"isLinked":false,"isThumbnail":true,"cid":"","cidWithOutTags":"","contentLocation":"","download":"BN0gFmNTTOarHTn7bDrdaLxLQ-HmO36mmT8av0rwGMsO9XeBlK7OWBq4uiR5N3RkgjXBwwDtOcLBTPIx-354pFHsV2BigaNfpvFG7XlkFYyCsOwGQcNS2pR_U53ISNCnDV-bZYNjl6dc-XAPb71qOkkxn-XxWCtfqJl5ngPPQ67owcZUUfIv9ddSsGyX5PhMljxyMq6f_Cz6dp07Xeaex89ED35VTqyJe4C1MyAxq92fJlxBstcj7dM12YbRJzzWeS_B9t6g48mwh-0am6c28uxPAGYc_EP4C3VweITw7Q5uhTtNmycMksTu4CIVepYn","folder":"INBOX","uid":"22","mimeIndex":"3","framed":false}
]
当我试图将该对象转换为值数组array时
sample.pdf,test4.jpg
使用下面的代码:
var aAtt = oAtt.map(({fileName}) => [fileName]);
当我直接以
oAtt[0].fileName
身份访问它时,我正在获取文件名值。同样,当我在主要代码(仅声明为oAtt
和map
代码行)上运行它时,它应该可以正常工作。有什么线索可能是错误的吗?
最佳答案
我无法重现您的问题。什么是oArr
?您正在谈论代码中的oAtt
和aAtt
。
var oAtt = [{
"sModelName": "AttachmentModel",
"disposables": [],
"mimeType": "application/pdf",
"fileName": "sample.pdf",
"fileNameExt": "pdf",
"fileType": "pdf",
"description": null,
"estimatedSize": 19333,
"friendlySize": "19KB",
"isInline": false,
"isLinked": false,
"isThumbnail": false,
"cid": "",
"cidWithOutTags": "",
"contentLocation": "",
"download": "zyfTZvzczVW6cqlcsIrm3ycmY5soz3DzK5sZhjnSOwaW0wnwGwHtqBvPeo8nVpiWD4yKVIPvAPauJHZufHGRG0Eb4MRmBpkGlvsDGP-gz3CnVp4GorN_xXCI0Gkd2I93IySKMy5iXRt-wML9wxLwTZcrOMLyPp-Kr6b0GlzlHuvk3RqEXRqSlCQTX5piRO6AaRYeMKeq8PSJcId1grMYzFpCnjVSoW_Zj7yTGAsy-D_mzFoCmBdksCweEqPdGhFYFkukblXzaZiTSNGTj1xYOvMIN4XXUZtU0EAPoQ9EFxfPWY_-1Siyge0Gks2zbGs3myxXJg..",
"folder": "INBOX",
"uid": "22",
"mimeIndex": "2",
"framed": false
},
{
"sModelName": "AttachmentModel",
"disposables": [],
"mimeType": "image/jpeg",
"fileName": "test4.jpg",
"fileNameExt": "jpg",
"fileType": "image",
"description": null,
"estimatedSize": 26326,
"friendlySize": "26KB",
"isInline": false,
"isLinked": false,
"isThumbnail": true,
"cid": "",
"cidWithOutTags": "",
"contentLocation": "",
"download": "BN0gFmNTTOarHTn7bDrdaLxLQ-HmO36mmT8av0rwGMsO9XeBlK7OWBq4uiR5N3RkgjXBwwDtOcLBTPIx-354pFHsV2BigaNfpvFG7XlkFYyCsOwGQcNS2pR_U53ISNCnDV-bZYNjl6dc-XAPb71qOkkxn-XxWCtfqJl5ngPPQ67owcZUUfIv9ddSsGyX5PhMljxyMq6f_Cz6dp07Xeaex89ED35VTqyJe4C1MyAxq92fJlxBstcj7dM12YbRJzzWeS_B9t6g48mwh-0am6c28uxPAGYc_EP4C3VweITw7Q5uhTtNmycMksTu4CIVepYn",
"folder": "INBOX",
"uid": "22",
"mimeIndex": "3",
"framed": false
}
];
var aAtt = oAtt.map(({fileName}) => [fileName]);
console.log(oAtt);
console.log(aAtt);