我想限制list infor in loop. 如果数据列表大于8。它只显示8个列表。我添加了这样的条件if (entry)。长度<= 8)但它不工作。
poweredareaOfInspec(List < Map < String, dynamic >> areaOfInspec) {
try {
if (areaOfInspec != null) {
var areaOfInspecHtml = "";
for (var entry in areaOfInspec) {
if (entry.length <= 8) {
areaOfInspecHtml += '<tr style="height: 35px;">';
areaOfInspecHtml +=
'<td align="center" style="font-family: arial; color: #414141;font-size: 12px;border-right: solid 0.7px #d6d5d5;">' +
entry['key'] +
'</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[0] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[1] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[2] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += '<td align="center" style="font-family: arial; color: #414141;font-size: 12px;">';
areaOfInspecHtml += entry['value'].split("#")[3] == "true" ? "✓" : "–";
areaOfInspecHtml += '</td>';
areaOfInspecHtml += "</tr>";
}
}
return areaOfInspectionHtml;
} else {
log("====*****areaOfInspecHtml not found");
return '';
}
} catch (e) {
throw Exception("Error" + e.toString());
}
}
使用take
。它将返回列表中的前N个元素(如果列表少于N个元素,则返回所有元素):
for (var entry in areaOfInspec.take(8)) {
...
}