JsViews Data-Link Helper Function -


i have following helper defined:

$.views.helpers({     total: function(lines) {         var total = 0;          (var = 0; < lines.length; i++) {             total += lines[i].price * lines[i].quantity;         }          return total;     } }); 

then have have following code data link model view:

var model = {     lines: [] };  $("#lines").link(true, model); 

finally within view have following:

<span data-link="~total(lines)"></span> 

however whenever observably add or remove items array doesn't update total. read pass in lines.length function , indeed updated total each time added or removed item. when observably updated quantity property against of lines total did not update.

i'd appreciate if show me how this.

thanks

yes, found https://github.com/borismoore/jsviews/issues/280, there not declarative syntax depending on "all". after v1.0 feature added - along lines of total.depends = "lines**"; or total.depends = "lines*.*"; helper: function total(...)...

meantime can use programmatic approach - still easy. trigger refresh adding:

$.observable(model.lines).observeall(function() {     $("#lines").link(true, model); }) 

or refresh 'total' span writing:

<span id="total" data-link="~total(lines)"></span> 

and

$.observable(model.lines).observeall(function() {     $("#total").link(true, model); }) 

see example: http://jsfiddle.net/borismoore/wch601l9/


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -