Created
September 2, 2020 12:18
-
-
Save lili21/6bcd75bfa75712560872303f33f2edda to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test() { | |
const [postionList, setPostionList] = setState([ | |
{ | |
id: 1, | |
title: 'a', | |
selected: false | |
}, | |
{ | |
id: 2, | |
title: 'b', | |
selected: false | |
}, | |
{ | |
id: 3, | |
title: 'c', | |
selected: 'false' | |
} | |
]) | |
const isAllSelected = useMemo(() => positionList.every(p => p.selected), [positionList]) | |
useEffect(() => { | |
const selectedId = positionList.filter(p => p.selected).map(p => p.id) | |
fetchData(selectedId) | |
}, [positionList]) | |
const selectPosition = (id) => { | |
if (id) { | |
const index = positionList.findIndex(p => p.id === id) | |
const p = positionList[index] | |
setPostionList([ | |
...positionList.slice(0, index), | |
{ | |
...p, | |
selected: !p.selected | |
}, | |
...postionList.slice(index + 1) | |
]) | |
} else { | |
setPostionList(positionList.map(p => { | |
p.selected = true | |
})) | |
} | |
} | |
return ( | |
<div> | |
<Filter> | |
<div onClick={() => selectPosition()} className={classnames({ active: isAllSelected })}>全部</div> | |
{ | |
positionList.map(p => ( | |
<div className={classnames({ active: !isAllSelected && p.selected })} onClick={() => selectPosition(p.id)}> | |
{p.title} | |
</div> | |
) | |
) | |
} | |
</Filter> | |
<JobList /> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment