jquery replaceWith does not parse the data-bind attribute

147 views
Skip to first unread message

justin....@gmail.com

unread,
Nov 5, 2013, 12:54:13 PM11/5/13
to knock...@googlegroups.com
Hello All,
   Within a function in my viewModel, I have the following statement:
     $("#gameDetails").replaceWith(data);
 data consists of the html that is in the attached file. The function replaceWith ignores all the elements containing a data-bind attribute. Is there a way to possibly "extend" jQuery so it will parse 
the custom attribute? 
Thanks. 
html.txt

Gunnar Liljas

unread,
Nov 5, 2013, 1:22:06 PM11/5/13
to knock...@googlegroups.com
No, what happens is that you throw away/add new stuff in the DOM, and Knockout has no way of knowing this. You will have to rebind the KO model to the element, using applyBindings.

Or....don't mess with the DOM using JQuery, let KO handle everything. 

/G

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

adam...@hotmail.com

unread,
Nov 5, 2013, 1:36:26 PM11/5/13
to knock...@googlegroups.com
Take a look at Ryan Niemeyer's example here: http://jsfiddle.net/rniemeyer/FCN5p/

I think the relevant part is that you apply bindings to the newly added markup

ko.applyBindings(viewModel, $("#dynamic")[0]);


JJ

unread,
Nov 6, 2013, 10:15:33 AM11/6/13
to knock...@googlegroups.com
Gunnar and Adam,
  Thank you for your help. It's working now.


On Tuesday, November 5, 2013 12:54:13 PM UTC-5, JJ wrote:
Reply all
Reply to author
Forward
0 new messages