javascript - Changing the value of the variable from outside of model -


function searcharticlemodel() {         var self = this;         self.param = ''}  var searchmodel = new searcharticlemodel(); ko.applybindings(searchmodel, document.getelementbyid("ko-search-module"));   $('.tag-menu').on('click', function(e) {             showsearch();             // searchmodel.param("tags") } 

i need give string value tag param. not able that. tried stuck @ this. using knockout first time bit confused. have knockout model param value null. , trying set value of param when following function called.

you should use ko.observable() make changes affect ui.

function searcharticlemodel() {     var self = this;     self.param = ko.observable() }  var searchmodel = new searcharticlemodel(); ko.applybindings(searchmodel, document.getelementbyid("ko-search-module"));   $('.tag-menu').on('click', function(e) {         showsearch();         // searchmodel.param("tags") } 

also i'd suggest use ko click binding instead of $('.tag-menu').on().

function searcharticlemodel() {     var self = this;     self.param = ko.observable()     self.setparam = function(){         self.param('tag');     } } 

then in html:

<a data-bind="click: setparam"></a> 

or can pass parameter html binding:

<a data-bind="click: setparam.bind($data, 'param value')"></a> 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -