简体   繁体   English

React:如何添加唯一的类名?

[英]React: How to add unique className?

How to add to className - "i" ?如何添加到className - "i" To make each class unique?让每个班级都独一无二? Or maybe it is done somehow differently?或者也许它以某种不同的方式完成? Tell me please?请告诉我?

 const onHandleCreateBlockInfo = () => { return infoArray.map(i => { return ( <div key={id++} className={i.keys()}> {i.company !== undefined ? <h2>Всего клиентов: {i.company.length}</h2> : null} {i.invoice !== undefined ? <h2>Оплаченных заказов: {i.invoice.length}</h2> : null} {i.projects !== undefined ? <h2>Открытых проектов: {i.projects.filter(i => i.status === true).length}</h2> : null} {i.users !== undefined ? <h2>Работников компании: {i.users.length}</h2> : null} </div> ); }) };

This is not how it works (这不是它的工作原理(

try className={"myClassName"+index} which is static part myClassName and adding the index to it;尝试className={"myClassName"+index}这是静态部分myClassName并向其添加索引; be sure to get the index inside map also.一定要得到地图内的索引。 Snippet below:下面的片段

  return infoArray.map((i, index) => {
return (
  <div key={index} className={"myClassName"+index}>
 {i.company !== undefined ? <h2>Всего клиентов: {i.company.length}</h2> : null}
 {i.invoice !== undefined ? <h2>Оплаченных заказов: {i.invoice.length}</h2> : null}
 {i.projects !== undefined ? <h2>Открытых проектов: {i.projects.filter(i => i.status === true).length}</h2> : null}
 {i.users !== undefined ? <h2>Работников компании: {i.users.length}</h2> : null}
  </div>
);
  })

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

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