does mapping plugin create dependencies?

21 views
Skip to first unread message

Juan Pablo Ramírez

unread,
Apr 26, 2017, 6:42:29 AM4/26/17
to KnockoutJS
Hello all.

I have an example of code, where I am trying to call an ajax function, like this:

var data = { . . .
    filter
: {
        param1
: ko.observable(),
        param2
: ko.observable(),
       
. . .
        paramN
: ko.observable()
   
}
}


function ViewModel() {
    var self = this;

   
self.sendData = function() {
        $
.ajax("address", ko.mapping.toJS(data.filter)).done(function() { . . . })
   
}
}


data.filter observables are binded with many text fields in html.
ViewModel.sendData function will be called only by a click binding in a button, but my code is calling it whenever a data.filter changes.

On the one hand, is there a method to avoid ko.mapping.toJS create any dependencies?
On the other hand, ViewModel.sendData function is not an observable, but, I have read ko transforms functions into computed's. I tried to avoid it by including model and event parameters into its signature, but I can't get the solution.


Can you give me a hand with this, please?
Thanks a lot in advance.


Reply all
Reply to author
Forward
0 new messages