for (let entry of data) {
trHtml += `<tr>
<td>` + '1' + `</td>
<td>` + entry.servicecode + `</td>
<td>` + entry.servicename + `</td>
<td>` + entry.duedate + `</td>
<td>` + entry.installmentamount + `</td>
<td>` + '1' + `</td>
</tr>`;
}
我有这个循环。我想要的是entry.duedate
添加| date:'shortdate'
,但在这种情况下我不能因为我得到错误:
禁止按位操作(无按位)
答案 0 :(得分:1)
这是一个简单的解决方案:
for (let entry of data) {
let date : Date=<Date>entry.duedate;
let day=date.getDate();
let month= date.getMonth()+1;
let year = date.getFullYear();
let dateString : String = day+"/"+month+"/"+year; // if u want dd/mm/yyyy for example
trHtml += `<tr>
<td>` + '1' + `</td>
<td>` + entry.servicecode + `</td>
<td>` + entry.servicename + `</td>
<td>` + dateString + `</td>
<td>` + entry.installmentamount + `</td>
<td>` + '1' + `</td>
</tr>`;
}