Dynamic binding in Knockout click event

时间:2015-10-06 08:42:15

标签: jquery knockout.js sweetalert

I am using an alert plugin on my website. The alert prompts the user to select on of the multiple options. Something like the image. enter image description here

The issues is that buttons are generated dynamically like this

var html = "<div id='reject-options'></br> ";
html += "<a href='#' class='button alert small radius' data-bind='click: $root.blacklistOrderForMatch'>" + Texts.Order + "</a> </br>";

The click bind doesn't apply because the bindings are already in place when the website loads. How can I achieve this? Looking forward to hear from you.

1 个答案:

答案 0 :(得分:4)

你只需要使用:

ko.applyBindings(self, document.getElementById('reject-options'));
//self is your view model

Fiddle

ko.applyBindings的第二个参数是您要应用绑定的节点。