第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

將下面代碼中相似的代碼行分組在一起以進行一些數(shù)組過濾

將下面代碼中相似的代碼行分組在一起以進行一些數(shù)組過濾

繁花不似錦 2023-11-12 15:03:32
我在 if else 條件中重復使用相同的數(shù)組過濾器功能,但每種情況下只有屬性不同。有沒有辦法將它們組合在一起,還是像下面這樣正確?private _filter(value: string, filterIndex, type: string): string[] {    let filterArray = [];    const filterValue = value.toLowerCase();    if (filterIndex == 0) {  // Index for Type      if (type === 'Dsc') {        this.assetTypeData.filter((option) => option.assetTypeDsc.toLowerCase().includes(filterValue)).forEach(element => {          filterArray.push(element.assetTypeDsc)        });      } else {        this.assetTypeData.filter((option) => option.assetTypeCde.toLowerCase().includes(filterValue)).forEach(element => {          filterArray.push(element.assetTypeCde)        });      }    } else if (filterIndex == 1) { // Index for Make      if (type === 'Dsc') {        this.assetMakeData.filter((option) => option.assetMakeDsc.toLowerCase().includes(filterValue)).forEach(element => {          filterArray.push(element.assetMakeDsc)        });      } else {        this.assetMakeData.filter((option) => option.assetMakeCde.toLowerCase().includes(filterValue)).forEach(element => {          filterArray.push(element.assetMakeCde)        });      }}
查看完整描述

1 回答

?
千巷貓影

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

試圖將所有可以分組的東西分組


private _filter(value: string, filterIndex, type: string): string[] {

    const filterValue = value.toLowerCase();

    return (filterIndex == 0 ? this.assetTypeData : this.assetMakeData)

       .map(option => option[(filterIndex == 0 ? 'assetType': 'assetMake') + type])

       .filter(assetValue => assetValue.toLowerCase().includes(filterValue));

}


查看完整回答
反對 回復 2023-11-12
  • 1 回答
  • 0 關注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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