Knockout.js Binding Click event to virtual elements -
i know how bind anchor element click event. unsure how when anchor elements being loaded in via html binding event. here code:
<a href='/my_page' data-bind="click:$root.loadpage">click here load</a>
** anchor element serves html server. within served html, have anchor elements want bind similar function. doing not working. here knockout code "loadpage"
this.loadpage = function(data,object) { self.showloadingindicator(); $.get(object.target.href, function(response) { self.pagedata(response.html); }, 'json'); }
** have observable setup called "pagedata" serves html content page.
my problem is: in "served" html, have the same click binding set on of html objects here, don't fire event...
any solutions?
thanks in advance!
rob
when call applybindings, affects things on page - not affect loaded later.
however, can call applybindings again on new chunk of markup added page.
var viewmodel = ...; ko.applybindings(viewmodel); this.loadpage = function(data,object) { self.showloadingindicator(); $.get(object.target.href, function(response) { self.pagedata(response.html); var newstuffaddedtodom = ...; ko.applybindings(viewmodel, newstuffaddedtodom); }, 'json'); }
here's working fiddle: http://jsfiddle.net/tlarson/65k3u/
Comments
Post a Comment