如何使JavaScript单元格具有全行宽度
我有一个从数组中获取数据的表。我的问题是,如果数组中的对象的值为零,我不知道如何使单元格占据整行。如果其值大于零,则将显示两个单元格,一个显示项目名称,另一个显示其值。非常感谢您的帮助如何使JavaScript单元格具有全行宽度,javascript,css,reactjs,Javascript,Css,Reactjs,我有一个从数组中获取数据的表。我的问题是,如果数组中的对象的值为零,我不知道如何使单元格占据整行。如果其值大于零,则将显示两个单元格,一个显示项目名称,另一个显示其值。非常感谢您的帮助 //breaks loop if x is == to counters array if (this.state.counters.length == x) { break; } const info = this.state.counters[x
//breaks loop if x is == to counters array
if (this.state.counters.length == x) {
break;
}
const info = this.state.counters[x]["text"];
const quantity = this.state.counters[x]["value"];
console.log(info, quantity);
//creates rows based on input
var table = document.getElementById("myList");
var row = table.insertRow(1);
document.getElementById("thTitle").style.maxWidth = "100px";
if (quantity <= 0) {
var itemCell = row.insertCell(0);
itemCell.innerHTML = info;
} else {
var itemCell = row.insertCell(0);
var quantityCell = row.insertCell(1);
itemCell.innerHTML = info;
itemCell.style.minWidth = "100px";
quantityCell.innerHTML = quantity;
}
//如果x等于计数器数组,则中断循环
if(this.state.counters.length==x){
打破
}
const info=this.state.counters[x][“text”];
常量数量=此.state.counters[x][“值”];
控制台日志(信息、数量);
//根据输入创建行
var table=document.getElementById(“myList”);
var行=table.insertRow(1);
document.getElementById(“thTitle”).style.maxWidth=“100px”;
如果(quantity有属性colspan to td tag,该数字是他拉伸的行数
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td colspan="2">Sum: $180</td>
</tr>
</table>
//In Js just add
itemCell.setAttribute('colspan', '2');
when the quantity <= 0
月
储蓄
一月
$100
二月
$80
总额:180美元
//在Js中,只需添加
setAttribute('colspan','2');
当数量有属性colspan to td tag时,该数字就是他拉伸的行数
<table>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
<tr>
<td colspan="2">Sum: $180</td>
</tr>
</table>
//In Js just add
itemCell.setAttribute('colspan', '2');
when the quantity <= 0
月
储蓄
一月
$100
二月
$80
总额:180美元
//在Js中,只需添加
setAttribute('colspan','2');
当数量时,将其放入:
if (quantity <= 0) {
var itemCell = row.insertCell(0);
itemCell.innerHTML = info;
// this line
itemCell.setAttribute('colspan', '2');
}
if(数量放入:
if (quantity <= 0) {
var itemCell = row.insertCell(0);
itemCell.innerHTML = info;
// this line
itemCell.setAttribute('colspan', '2');
}
if(数量