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

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

將過濾器應用于列表并顯示數據

將過濾器應用于列表并顯示數據

慕森卡 2023-08-10 14:38:06
前端: const [searchParameters, setSearchParameters] = useState({    type: "",    country:"",      });  const onChangeSearchType = e => {    const workingObject = {...searchParameters};    workingObject.searchType = e.target.value;     setSearchParameters(workingObject);     };  const onChangeSearchCountry = e => {    const workingObject = {...searchParameters};    workingObject.searchCountry = e.target.value;     setSearchParameters(workingObject);  };const handleFetchWithSearchParameters = () => {    TutorialDataService.findByParameters(searchParameters)             .then(response => {         setTutorials(response.data);         console.log(response.data);             })             .catch(e => {         console.log(e);             });    }之后return():<Form.Control as="select" defaultValue=""            type="text"            className="form-control"            id="country"            required            value={searchParameters.country}            onChange={onChangeSearchCountry}            name="country">            <option>Nigeria</option>            <option>Ghana</option>            <option>Kenya</option>            <option>Senegal</option>                 </Form.Control>                 <Form.Control as="select" defaultValue=""            type="text"            className="form-control"            id="type"            required            value={searchParameters.type}            onChange={onChangeSearchType}            name="type">            <option>Agricultural</option>            <option>Manufacturing</option>            <option>Industrial</option>            <option>Livestock</option>            <option>Service Industry</option>                 </Form.Control> <div className="input-group-append"><button className="btn btn-outline-secondary" type="button" onClick={handleFetchWithSearchParameters}       Search </button>
查看完整描述

1 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

只是一個意見:我會稍微修改前端和后端以支持組合請求。您可以使用不同的參數將 JavaScript 對象(作為 JSON)發(fā)送到 API,并在后端控制器函數中應用檢查。


所以基本上,而不是單獨


 const findByType = () => {...}

    const findByRevenue = () => {...}

    const findByEmployeesNumber = () => {...}

   

我會使用(狀態(tài)可以是一個整體對象,如下例所示,也可以是分離的,然后在發(fā)送到 API 時組裝成一個對象)


   const [searchParameters, setSearchParameters] = useState({

        type: '',

        revenue: '',

        employeesNumber: ''

      });

    

    const onChangeSearchType = e => { 

      const workingObject = {...searchParameters};

      const workingObject.searchType = e.target.value; 

      setSearchParameters(workingObject);   

    };

    

    // same logic for onChangeRevenue and onChangeEmployeesNumber

    

    const handleFetchWithSearchParameters = () => {

      TutorialDataService.findByParameters(searchParameters)       

        .then(response => { 

          setTutorials(response.data); 

          console.log(response.data);       

        })       

        .catch(e => { 

          console.log(e);       

        });  

    }

然后在控制器中,我將破壞查詢對象并對其運行查詢


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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