Skip to content

Instantly share code, notes, and snippets.

@cristhian-net
Created May 21, 2017 01:12
Show Gist options
  • Save cristhian-net/79431c38f62000923e03b6c588e709b6 to your computer and use it in GitHub Desktop.
Save cristhian-net/79431c38f62000923e03b6c588e709b6 to your computer and use it in GitHub Desktop.
<template>
<require from="./contador"></require>
<require from="./precio"></require>
<require from="converters/number-format"></require>
<div>
Total: <span>$ ${total | numberFormat:'0,0.00':'0'}</span>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Producto</th>
<th>Cantidad</th>
<th>Precio</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr repeat.for="item of lista">
<td>${item.Nombre}</td>
<td>
<contador objeto.bind="item"></contador>
</td>
<td>
<precio objeto.bind="item"></precio>
</td>
<td class="TRight">
$ ${(item.Precio ? item.Precio : 0) * item.Cantidad | numberFormat:'0,0.00':'0'}
</td>
</tr>
</tbody>
</table>
</template>
import {bindable, computedFrom} from 'aurelia-framework';
export class ContadorListaObjetos {
@bindable public lista = [];
get total() {
let totall = this.lista.reduce((prev, current, index, arr) => {
let precioPrev = prev.Precio ? prev.Precio : 0;
let precioCurrent = current.Precio ? current.Precio : 0;
return precioPrev * prev.Cantidad + precioCurrent * current.Cantidad;
});
return totall;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment