簡體   English   中英

然后在 React 中過濾一個數組和 map

[英]Filter an array and map in then in React

我正在研究一個過濾器/map function,它如下:

 <div className ="filteredSitter" > <h4> Available sitters </h4> <h5> Click on their name to get in touch with them</h5> {sitters.filter(InitialSitter => InitialSitter.locationSitter === "London").map(filteredSitter => ( <li onClick = {function (){alert(`${filteredSitter.nameSitter} is located in ${filteredSitter.locationSitter} and his phone number is ${filteredSitter.phoneSitter}`);}}> {filteredSitter.nameSitter} </li> ))} </div>

我的問題是 - 而不是使用“倫敦”作為強制比較,我想使用以所有者形式插入她的數據的最新人(我嘗試使用props.owners.locationOwner但它沒有用。)任何想法如何與作為 state 一部分的人的位置進行比較?

這是 state 和我擁有的初始所有者(所以我想與進入此陣列的其他用戶的位置進行比較)。

 let InitialOwners = [ { nameOwner: 'Jim', locationOwner: "Barcelona", phoneOwner: "+34 671 872 000", startDateOwner: "01/03/2021", endDateOwner: "08/03/2021" }, { nameOwner: 'Jessica', locationOwner: "Paris", phoneOwner: "+34 651 871 000", startDateOwner: "20/03/2021", endDateOwner: "28/03/2021" } ]; function App() { const [owners, setOwners] = useState(InitialOwners); .....

謝謝你 !!

嘗試這個:

owners[owners.length - 1].locationOwner

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM