我一直在努力研究如何在我的 Ionic 应用程序中创建搜索栏。当我尝试了解如何创建搜索栏时,我只找到了带有 Ionic 的 Angular 示例,而 Ionic 文档上的 React 示例并没有帮助。此外,当我简单地搜索如何使用 React 和 Typescript 进行操作时,我总是陷入死胡同。我似乎无法理解如何实现搜索栏以允许用户输入标题,然后它只会单独显示该卡。任何帮助将不胜感激找出解决这个问题的方法。
import React, { useState } from "react";
import {
IonHeader,
IonContent,
IonToolbar,
IonTitle,
IonPage,
IonButton,
IonCard,
IonCardHeader,
IonCardSubtitle,
IonCardTitle,
IonCardContent,
IonGrid,
IonRow,
IonCol,
IonItem,
IonLabel,
IonFooter,
IonModal,
IonIcon,
IonSearchbar,
} from "@ionic/react";
export const SEARCH = [
{
id: "s1",
title: "Business",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-business",
},
{
id: "s2",
title: "Computing",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-computing",
},
{
id: "s3",
title: "Connections",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-connections",
},
{
id: "s4",
title: "Construction",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-construction",
},
{
id: "s5",
title: "Engineering",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-engineering",
},
{
id: "s6",
title: "Graduate",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-graduate",
},
{
id: "s7",
title: "Marketing",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-marketing",
},
{
id: "s8",
title: "Medicine",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-medicine",
},
{
id: "s9",
title: "Science",
detail:
"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.",
page: "/search-science",
},
];
export const Search: React.FC = () => {
const [showModal, setShowModal] = useState(false);
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle>Search</IonTitle>
</IonToolbar>
<IonToolbar>
<IonSearchbar>
</IonSearchbar>
</IonToolbar>
</IonHeader>
<IonContent className="ion-padding">
<IonGrid>
<IonRow>
{SEARCH.map((search) => (
<IonCol
size="12"
size-xs="12"
size-sm="6"
size-md="4"
size-lg="4"
key={search.id}
>
<IonCard>
<IonCardHeader>
<IonCardTitle>{search.title}</IonCardTitle>
<IonCardSubtitle>Sector</IonCardSubtitle>
</IonCardHeader>
<IonCardContent>{search.detail}</IonCardContent>
<IonFooter className="ion-text-right">
<IonButton
color="secondary"
fill="clear"
routerLink={search.page}
>
View
</IonButton>
</IonFooter>
</IonCard>
</IonCol>
))}
<IonCol className="ion-text-center">
<IonModal isOpen={showModal} cssClass="my-custom-class">
<p>This is modal content</p>
<IonButton
color="secondary"
onClick={() => setShowModal(false)}
>
Close Modal
</IonButton>
</IonModal>
<IonButton color="secondary" onClick={() => setShowModal(true)}>
Information
</IonButton>
</IonCol>
</IonRow>
</IonGrid>
</IonContent>
</IonPage>
);
};
export default Search;