javascript - Simple Method to refresh Viewmodel with KnockoutJS using anchor tag -


i have simple viewmodel has ko.computed method. ko.computed methoud has multiple ajax call in it. call ko.computed method anchor tag refresh data set.

my viewmodel:

var mydataviewmodel = {      date: ko.observable(formatdate()),      receiving: ko.observablearray(),      triage: ko.observablearray(),      technician: ko.observablearray(),      scrap: ko.observablearray(),      refurb: ko.observablearray(),      ca: ko.observablearray(),      dispatch: ko.observablearray() }  mydataviewmodel.refresh = ko.computed(function () {    var self = mydataviewmodel;        //ajax calls here     }); 

my anchor tag:

<a href="#refresh" data-bind="click: refresh" ><i class="icon-refresh"></i></a> 

when click anchor tag, following message:

uncaught error: cannot write value ko.computed unless specify 'write' option. if wish read current value, don't pass parameters.

any suggestions assistance appreciated.

the click binding needs function executed when click, don't need ko.computed here function:

mydataviewmodel.refresh = function () {         var self = mydataviewmodel;          //ajax calls here }; 

you need use ko.computed when want calculate new values existing observable properties. computed observable documentation:

what if you’ve got observable firstname, , lastname, , want display full name? that’s computed observables come in - these functions dependent on 1 or more other observables, , automatically update whenever of these dependencies change.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -