简体   繁体   English

CardHeader 元素副标题中的换行符(MaterialUI / ReactJS)

[英]Line break in a CardHeader element subtitle (MaterialUI / ReactJS)

I'm using pretty old Material UI (Ver. 0.20.1) components.我正在使用相当旧的 Material UI (Ver. 0.20.1) 组件。

Here's a chunk of my code:这是我的一段代码:

return(
  <>
    <Card>
      <CardHeader 
      actAsExpander={true}
      showExpandableButton={true}
      title = {user.name} 
      subtitle={`${user.email}, ${user.phone}, ${user.isproved ? "Yes" : "No"}, Friends: ${user.friends? user.friends : "None"}`} 
      />
    </Card>)

So i have a subtitle string with a bunch of variables in it that i wanted to use a line break to separate visually but adding \n or even '...string' + <br/> + 'string...' doesn't work.所以我有一个带有一堆变量的字幕字符串,我想使用换行符在视觉上分隔,但添加\n甚至'...string' + <br/> + 'string...'没有'不工作。 What should i do?我应该怎么办?

I can't test in a sandBox but if we look in the version 0.20.1 documentation of Material-ui we can read that:我无法在沙盒中进行测试,但如果我们查看 Material-ui 的 0.20.1 版文档,我们可以看到:

property: subtitle type: node Can be used to render a subtitle in Card Header .属性:字幕类型:节点可用于渲染卡片 Header 中的字幕

so you can create a node for example a list:因此您可以创建一个节点,例如一个列表:

const subtitle =<ul><li>{user.email},</li><li>{user.phone},</li><li> {user.isproved ? "Yes" : "No"},</li><li> Friends: {user.friends? user.friends : "None"}</li></ul>;

and pass it to subtitle like this:并将其传递给这样的subtitle

return(
  <>
    <Card>
      <CardHeader 
      actAsExpander={true}
      showExpandableButton={true}
      title = {user.name} 
      subtitle={subtitle} 
      />
    </Card>
</>
)

UPDATE:更新:
I found a codeSanbox template so here a working example我找到了一个 codeSanbox 模板,所以这里是一个工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM