首页 > 解决方案 > Include JavaScript inside Material-UI tags

问题描述

I have this material-ui ListItemText:

<ListItemText primary={<div>
  <Table className={classes.table}>
    <TableRow>
      <TableCell width="40">{item.issue_state}</TableCell>
      <TableCell width="40">{item.issue_number}</TableCell>
      <TableCell width="600">{item.issue_title}</TableCell>
      <TableCell width="600">{item.issue_url}</TableCell>
    </TableRow>
  </Table>
</div>}/>

Rather than displaying the URL, I'd like to have something like this:

if (item.issue_url.includes("github.com") {
  item.issue_url = 'Public'
}
else if (item.issue_url.includes("github.company.com") {
  item.issue_url = 'Private'
}

where the TableCell displays Public of Private rather than the whole URL. Can this be done?

标签: javascriptnode.jsreactjsmaterial-ui

解决方案


you could use as below,

<ListItemText primary={<div>
  <Table className={classes.table}>
    <TableRow>
      <TableCell width="40">{item.issue_state}</TableCell>
      <TableCell width="40">{item.issue_number}</TableCell>
      <TableCell width="600">{item.issue_title}</TableCell>
      <TableCell width="600">{
            (item.issue_url.indexOf('github.company.com') >=0)
            ? 'Private' 
            : ((item.issue._url.indexOf('github.com') >=0) 
              ? 'Public'
              : '')
      }</TableCell>
    </TableRow>
  </Table>
</div>}/>

Otherwise, good idea is to create a derived property in item based on issue_url


推荐阅读