Sunday 15 August 2010

How can I calculated the total sum of a repeat binding in polymer? -



How can I calculated the total sum of a repeat binding in polymer? -

example:

<div id="order"> <template repeat="{{items item}}"> <p> <span>{{item.id}}</span> <span class="price">{{item.price}}</span> <span class="qty">{{item.qty}}</span> </p> {{cputotal(item.qty*item.price)}} </template> <p>total {{total}}</p> </div> <script> polymer('my-form', { total:0, cputotal:function(x){ this.total=this.total+x console.log(this.total) } }) </script> </polymer-element>

is there way using computed binding can {{total=total+(item.price*item.qty)}} ?

edit: problem have this.total total of each separate item? each generated item in template have separate total instead of sum of them all.

i stick logic function (say, computedtotal()) , instead of this:

<p>total: {{total}}</p>

i have this:

<p>total: {{computedtotal()}}</p>

your computedtotal() this:

computedtotal: function() { var total = 0; (var = 0; < this.items.length; i++) { total += (this.items[i].price * this.items[i].qty); } homecoming total; }

i avoid putting much login in template itself.

polymer

No comments:

Post a Comment