2 回答

TA貢獻1936條經驗 獲得超7個贊
使用Array#find
:
const {attachments} = state.form.conditions.find(({type})=>type==='Anticipated Settlement Date');

TA貢獻1942條經驗 獲得超3個贊
Array.filter+Array.map是一種傳統方法:
var state = {
form: {
conditions: [{
exists: '',
attachments: [],
type: 'Finance',
description: '',
status: 'In Progress',
date: ''
}, {
exists: '',
attachments: [],
type: 'Valuation',
description: '',
status: 'In Progress',
date: ''
}, {
exists: '',
attachments: [],
type: 'Inspection',
description: '',
status: 'In Progress',
date: ''
}, {
exists: '',
attachments: [],
type: 'Other Sale',
description: '',
status: 'In Progress',
date: ''
}, {
exists: 'true',
attachments: [ 'select me!' ],
type: 'Anticipated Settlement Date',
description: '',
status: 'In Progress',
date: ''
}],
rejection_reason: '',
},
progress: false,
editable: true,
commercialLease: false,
redirecting: false,
formErrors: {}
};
let sel = state
.form
.conditions
.filter(item => item.type == 'Anticipated Settlement Date')
.map(item => item.attachments);
console.log(sel);
添加回答
舉報