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

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

如何通過反應(yīng)動態(tài)處理大量過濾器?

如何通過反應(yīng)動態(tài)處理大量過濾器?

拉風的咖菲貓 2021-12-02 19:30:02
我目前正在一家在線商店工作,該商店根據(jù)某些標準(例如尺寸、庫存、性別等)過濾產(chǎn)品。雖然我已經(jīng)能夠在一定程度上讓它發(fā)揮作用。我的程序目前按尺寸、性別、按價格排序等進行過濾。但是,我無法按品牌過濾。出于某種原因,一旦我點擊該品牌,我就可以過濾一次該功能,但是,一旦我點擊另一個品牌,該特定品牌的過濾器就不會運行。這是代碼沙箱的鏈接:https://codesandbox.io/s/mystifying-roentgen-7mp0t我目前堅持按品牌過濾,我嘗試通過檢查品牌是否包含在項目中并使用 localeCompare() 將過濾結(jié)果與點擊項目的狀態(tài)進行比較。這是代碼沙箱的鏈接:https://codesandbox.io/s/mystifying-roentgen-7mp0tcreateCheckboxes = () => available_sizes.map(this.createCheckbox);  handleFormSubmit = event => {    //4) this button updates the filters on the sizes, which I think I need to fix to update the brands, the price and the gender    event.preventDefault();    //5) right here I am storing the selected checkboxes which is what I was doing before by pushing the checkboxes    const selectedSizes = [...this.selectedCheckboxes];    const shallowCopy = [...this.state.filteredProducts];    let filteredProducts = shallowCopy.filter(product =>      selectedSizes.every(size =>        product.stock.some(s => s.stock > 0 && s.size === size)      )    );    let filteredGender = filteredProducts.filter(product => {      return product.gender.some((item, idx, arr) => {        return item[this.selectedGender] === false ? null : product;      });    });    //***this is the function that is not currently running***//    let filteredData = filteredGender.filter(product => {      //console.log(product.brand.includes(this.state.activeBrand))      //console.log(product.brand = this.state.brand)      return product.brand.includes(this.state.activeBrand)    });    let sortedPrice = filteredData.sort((a, b) => {      return this.state.sortBy === "min"        ? a.price - b.price        : b.price - a.price;    });    this.setState({      filteredProducts: sortedPrice    });  };一旦點擊了一個項目,我希望能夠通過這個功能按品牌進行過濾。這是代碼沙箱的鏈接:https://codesandbox.io/s/mystifying-roentgen-7mp0t
查看完整描述

1 回答

?
鴻蒙傳說

TA貢獻1865條經(jīng)驗 獲得超7個贊

您的應(yīng)用程序中有 2 個錯誤:

1) 第一個是@user753642 在對您的問題的評論中報告的,從 中刪除這一行index.js,因為它將您brand的所有產(chǎn)品設(shè)置為""

console.log(product.brand = this.state.brand)

2)您正在過濾,filteredProducts而不是全部products。雖然在第一次過濾品牌后filterdProducts沒有其他品牌的任何項目,但在過濾另一個品牌后返回一個空集合。更改 inhandleFormSubmit中的行index.js,從:

const shallowCopy = [...this.state.filteredProducts];

到:

const shallowCopy = [...this.state.products];


查看完整回答
反對 回復 2021-12-02
  • 1 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號