Created
May 21, 2017 01:12
-
-
Save cristhian-net/79431c38f62000923e03b6c588e709b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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