首先展示对应效果
下面是funtion 组件实现的代码
export const OfficeMenu = function OfficeMenu({ wardMap, handleSelectWard }) {
const [wardList, setWardList] = useState([]);
const [initWardList, setInitWardList] = useState([]);
useEffect(() => {
const wardList = [];
for (let key in wardMap) {
let obj = {
ch: key,
list: wardMap[key]
};
wardList.push(obj);
}
setWardList(wardList);
setInitWardList(deepClone(wardList));
}, []);
const onSearchWard = key => {
let newWardList = [];
initWardList.map(wardObj => {
const wardNameList = [];
wardObj.list.map(ward => {
if (ward.wardName.indexOf(key) != -1) {
wardNameList.push(ward);
}