如果有一个表,最后一列称为result。
我想突出显示所有“失败”的单元格/文本。
我该怎么做?
我需要使用html5和一个来自kdb的表。
目前我的电子邮件功能是
htmlMailBody:{[emailadd;subject;message]
cmd:"echo \"",message, "\" | mutt -e \"my_hdr
From:[email protected]\" -e \"my_hdr Content-Type:
text/html\" ",emailadd, " -s \"",subject,"\"";
sent:@[{system x;1b};cmd;{.log.error"Failure sending email. Reason: ",x;0b}];
if[sent; .log.info "Sent email to ",emailadd ];
};
mailRCP:bbc.gmail.com
htmlMailBody[mailRCP ;"health check";(,/)("<h2>SOD CHECKS<hr /></h2>";"<br />";markup[result];"<br />")];
这没用。如果将标记[结果]替换为kdb表,它将起作用。
最佳答案
要直接从q标记HTML表,请使用.h
namespace中的标记函数。
让你的桌子t
。
q)t
a b c d result
-------------------
94 66 8 82 success
8 24 62 47 failed
97 60 95 26 success
52 69 59 93 success
为HTML
at
元素创建相应的属性表td
。从没有属性的空字典开始。空字典是()!()
。q)show at:flip (cols t)! (count each(cols t;t))#enlist ()!()
a b c d result
------------------------------
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()
根据
result
的at
列更新result
的t
列。q)f:t[`result]=`failed
q)update result:([]color:(sum f)#enlist"red")from `at where f
q)at
a b c d result
----------------------------------------
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() (,`color)!,"red"
()!() ()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!() ()!()
我们可以使用
.h.htac
用属性字典标记表单元格。首先将表格单元格作为字符串:q)string t cols t
"94" ,"8" "97" "52"
"66" "24" "60" "69"
,"8" "62" "95" "59"
"82" "47" "26" "93"
"success" "failed" "success" "success"
别介意他们被翻了。现在
at
中的词典也翻了。q)at cols t
()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!()
()!() ()!() ()!() ()!()
()!() (,`color)!,"red" ()!() ()!()
我们可以将它们分别用作
.h.htac
的第二个和第一个参数。each-both adverb将在相应的行上迭代,但我们需要相应的单元格,因此.h.htac''
将在行内的单元格内迭代。q).h.htac''[`td;at cols t;string t cols t]
"<td>94</td>" "<td>8</td>" "<td>97</td>" "<td>52..
"<td>66</td>" "<td>24</td>" "<td>60</td>" "<td>69..
"<td>8</td>" "<td>62</td>" "<td>95</td>" "<td>59..
"<td>82</td>" "<td>47</td>" "<td>26</td>" "<td>93..
"<td>success</td>" "<td color=\"red\">failed</td>" "<td>success</td>" "<td>su..
函数
markup
汇编HTMLtable
元素:markup:{[t]
th:.h.htc[`tr;]raze .h.htc[`th;] each string cols t; / table head
at:flip (cols t)! (count each(cols t;t))#enlist ()!(); / empty attribute dictionaries
f:t[`result]=`failed;
at:update result:([]color:(sum f)#enlist"red")from at where f; / attributes for result failed
tr:.h.htc[`tr;]each raze each flip .h.htac''[`td;at cols t;string t cols t]; / table rows
.h.htc[`table;] .h.htc[`thead;th],.h.htc[`tbody;raze tr]
}
使用属性字典表是一种健壮的技术,可以适应各种突出显示,或者为客户端脚本提供id。