我正在从一个.json文件中获取一些数据到一个Reaction表中.在获得数据之后,我计算了一些数据并显示在另一个表格单元格中.我想要的是,当计算这些单元格时,我希望结果根据tailwind 中的IF条件更改 colored颜色 .
对于EX: If{item.hisseGuncelFiyat*item.hisseAdet-item.hisseMaliyer*item.hisseAdet<;0 那我想要红色或绿色
以下是代码:
const Table = () => {
return (
<div className='overflow-auto w-full'>
<table className=" mt-10 w-full ">
<thead className='bg-blue-900 text-white h-8 '>
<tr className='divide-x-2 divide-gray-200 '>
<th>Aracı Kurum</th>
<th>Hisse Adı</th>
<th>Maliyet</th>
<th>Güncel Fiyat</th>
<th>Adet</th>
<th>Kar/Zarar</th>
<th>Düzenle/Sil</th>
</tr>
</thead>
<tbody className='text-center divide-y-2 '>
{
data.map((item)=>(
<tr key={item.hisseId} className=' odd:bg-white even:bg-slate-100 divide-x-2 divide-gray-200'>
<td className='py-2 whitespace-nowrap'>{item.araciKurum}</td>
<td className='py-2 whitespace-nowrap'>{item.hisseAd}</td>
<td className='py-2 whitespace-nowrap'>{item.hisseMaliyet}<span>₺</span></td>
<td className='py-2 whitespace-nowrap'>{item.hisseGuncelFiyat}<span>₺</span></td>
<td className='py-2 whitespace-nowrap'>{item.hisseAdet}</td>
<td className='py-2 whitespace-nowrap'>
{item.hisseGuncelFiyat * item.hisseAdet - item.hisseMaliyet * item.hisseAdet < 0
? "text-red-400"
: "text-green-400"
}
<span>₺</span></td>
<td className='text-center gap-6 flex justify-center py-2 whitespace-nowrap'>
<button><BiEdit size={25} className='text-green-500'/></button>
<button><BiTrashAlt size={25} className='text-red-500'/></button>
</td>
</tr>
))
}
</tbody>
</table>
</div>
)
}
我试过这样的东西,但可能不知道怎么写
<td className='py-2 whitespace-nowrap'>
{item.hisseGuncelFiyat * item.hisseAdet - item.hisseMaliyet * item.hisseAdet < 0
? "text-red-400"
: "text-green-400"
}
<span>₺</span></td>