JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<table class="table table-striped">
<thead>
<tr>
<th>Codigo</th>
<th>Codigo Produto</th>
<th>Quantidade</th>
<th>Preco Unit.</th>
<th>Total Produto</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
<h1>Valor Total: <span id="totalSoma"></span></h1>
JavaScript
$(document).ready(function () {
var itensVenda = [{
Codigo: 1,
CodigoProduto: 11,
Quantidade: 5,
PrecoUnitario: 10
}, {
Codigo: 2,
CodigoProduto: 22,
Quantidade: 2,
PrecoUnitario: 10
}];
if (itensVenda != null) {
var total = 0;
$('#tbody').children().remove();
$(itensVenda).each(function (i) {
total += (itensVenda[i].PrecoUnitario * itensVenda[i].Quantidade);
var tbody = $('#tbody');
var tr = "<tr>";
tr += "<td>" + itensVenda[i].Codigo;
tr += "<td>" + itensVenda[i].CodigoProduto;
tr += "<td>" + itensVenda[i].Quantidade;
tr += "<td>" + itensVenda[i].PrecoUnitario;
tr += "<td>" + (itensVenda[i].PrecoUnitario * itensVenda[i].Quantidade);
tbody.append(tr);
});
}
$("#totalSoma").text(total);
});