0

我试图example: <IonBadge color="primary">New</IonBadge>在等于“今天”的<IonCardHeader>情况下添加一个“新”徽章。(job.createdAt)

你会建议我怎么做?

日期如 in,当前日期,而不是字符串。

我正在使用 Ionic React v4。

卡片功能如下。

非常感谢您的见解!!

function renderJobList(job) {
    return [{}].concat(job).map((job, i) =>
      i !== 0 ? (


            <LinkContainer key={job.jobId} to={`/jobinfo/${job.jobId}`}>
            <IonItemGroup>
            <IonCard>
              <IonCardHeader>
                <IonCardSubtitle><b>{(job.packageSelected)}</b></IonCardSubtitle>
                <IonCardTitle><h3>{(job.streetAddress)} {(job.city)} {(job.state)} {(job.zipCode)}</h3></IonCardTitle>
              </IonCardHeader>

              <IonCardContent>
                <p><b> Start Date: </b> {parseISO(job.startDate).toLocaleString()}</p>
               <p><b> Created At: </b> {new Date(job.createdAt).toLocaleString()}</p>
              </IonCardContent>
            </IonCard>
            </IonItemGroup>
            </LinkContainer>
4

2 回答 2

0

试试添加这个:

let today = new Date(new Date().getFullYear(),new Date().getMonth() , new Date().getDate())

然后使用:

<IonCardHeader>{job.createdAt == today ? (<IonBadge color="primary">New</IonBadge>) : null}</IonCardHeader>
于 2019-12-04T17:57:18.670 回答
0

您可以创建 Date 对象,然后匹配日期字符串

const today = new Date().toISOString().slice(0, 10);
const isToday = new Date(job.createdAt).toISOString().slice(0, 10) == today;
// implement your logic based on isToday boolean
于 2019-12-04T18:01:01.610 回答