亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何根據其內容選擇數組?

如何根據其內容選擇數組?

一只名叫tom的貓 2022-11-11 16:20:04
對于下面的示例,我想選擇附件值,如果它的類型為“預期結算日期”?我試過這樣做:state.form.conditions[[4]].attachmentsvar 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: [],**            type: 'Anticipated Settlement Date',            description: '',            status: 'In Progress',            date: ''        }],        rejection_reason: '',    },    progress: false,    editable: true,    commercialLease: false,    redirecting: false,    formErrors: { }};export { state };
查看完整描述

2 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

使用Array#find

const {attachments} = state.form.conditions.find(({type})=>type==='Anticipated Settlement Date');


查看完整回答
反對 回復 2022-11-11
?
手掌心

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);


查看完整回答
反對 回復 2022-11-11
  • 2 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號