【发布时间】:2017-05-18 05:33:05
【问题描述】:
我的表格包含以下结构:
广告中的状态具有唯一编号, 并且日期也具有日期本身的唯一值。
我想要的是在匹配(单元格状态和单元格日期)之后添加单元格,
所以,我有以下 JSON:
{
"data": [
[
{
"orderStatus": 2,
"date_formatted": "15-05-2017",
"counter": 2
},
{
"orderStatus": 4,
"date_formatted": "15-05-2017",
"counter": 14
},
{
"orderStatus": 5,
"date_formatted": "15-05-2017",
"counter": 12
},
{
"orderStatus": 11,
"date_formatted": "15-05-2017",
"counter": 6
}
],
[
{
"orderStatus": 2,
"date_formatted": "16-05-2017",
"counter": 6
},
{
"orderStatus": 4,
"date_formatted": "16-05-2017",
"counter": 15
},
{
"orderStatus": 5,
"date_formatted": "16-05-2017",
"counter": 12
},
{
"orderStatus": 11,
"date_formatted": "16-05-2017",
"counter": 5
}
],
[
{
"orderStatus": 2,
"date_formatted": "17-05-2017",
"counter": 4
},
{
"orderStatus": 4,
"date_formatted": "17-05-2017",
"counter": 10
},
{
"orderStatus": 5,
"date_formatted": "17-05-2017",
"counter": 13
},
{
"orderStatus": 11,
"date_formatted": "17-05-2017",
"counter": 6
}
]
],
"status_name": {
"1": "New",
"2": "Pending",
"3": "On Way",
"4": "Completed",
"5": "Cancelled Client",
"6": "Time out",
"7": "Secluded",
"8": "On Progress",
"9": "Receipt created",
"10": "Provider Arrive",
"11": "Provider cancelled",
"12": "Provider start the work",
"13": "Provider paused the work",
"14": "No Provider Available"
}
}
所以我想在两个具体数据下输入订单状态(匹配thead订单状态+匹配json元素和tbody td日期)。
我尝试了这个 jquery 代码,但它不起作用:
$("table thead:tr:th[value='2'] tbody:tr:td:[value='2017-20-9']").after(data["data"][count]["counter"]);
这是我在 sn-p 中的示例代码:
$("table thead:tr:th[value='2'] tbody:tr:td:[value='2017-20-9']").after("<td>Test</td>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<table id="table">
<thead>
<tr>
<th value='2'> Completed </th>
<th value='4'> Cancelled </th>
<th value='5'> Pending </th>
<th value='1'> Arrived </th>
<th value='9'> Waiting </th>
<th value='10'> Cancelled Provider</th>
</tr>
</thead>
<tbody>
<tr>
<td value='2017-20-8'>2017-20-8</td>
</tr>
<tr>
<td value='2017-20-9'>2017-20-9</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
<td>没有value属性,只有表单控件才会像<input>、<output>等。为什么标题的内容是动态的?表格的标题通常是静态的,而单元格是动态的。
标签: javascript jquery html html-table pug