简体   繁体   English

在表格单元格中填充颜色

[英]Fill colors in the table cell

I am trying to add colors on basis on my result.我正在尝试根据我的结果添加颜色。 If 'UnSuccessfull' - 'red' If 'Succesfull' - 'green'.如果“不成功”-“红色” 如果“成功”-“绿色”。 Issue is that I am directly converting my JSON file to format it in a table using jSON2HTML python library in one line, hence am not sure where and how to fill/add colors.问题是我在一行中使用 jSON2HTML python 库直接将我的 JSON 文件转换为表格格式,因此不确定在哪里以及如何填充/添加颜色。 Can anyone please assist?有人可以帮忙吗?

import json
import json2html


file_content = content_object.get()['Body'].read().decode('utf-8-sig')
data_to_be_sent = json.loads(file_content) 
# Convert to table
table = json2html.convert(json = data_to_be_sent)

Data to be sent is in table row format.要发送的数据为表格行格式。 Where and what should I put in to add colors in one of the cell since it shows result由于它显示结果,我应该在哪里以及在其中一个单元格中添加颜色

You can add a js file or simplaly a internal js to check values of all td and a simple if else condition can workaround in adding color to respective td for example例如,您可以添加一个 js 文件或简单地添加一个内部 js 来检查所有 td 的值,一个简单的 if else 条件可以解决为相应的 td 添加颜色的方法

 $('#mytable tr td').each(function() { var tdValue = $(this).html(); if (tdValue > 10){ $(this).css("color", "green"); }else if (tdValue < 10){ $(this).css("color", "red"); } }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <html> <table> <tbody> <tr> <td>2</td> <td>12</td> <td>20</td> <td>6</td> <td>7</td> </tr> </tbody> </table> </html>

this example is just for explaining the concept it might not work but i hope you got my point这个例子只是为了解释它可能不起作用的概念,但我希望你明白我的意思

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

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