获取动态插入的HTML以与knockoutjs一起工作 [英] Get dynamically inserted HTML to work with knockoutjs
问题描述
我为所有表使用了JQuery DataTables,因为所有内置的功能都很好,但似乎自定义表布局的唯一方法是为DataTable设置sDom选项属性并使用类似 $(div.SOMECLASS)。html(HTML_HERE)
将自定义html插入到表中。 (仅供参考,我只是试图自定义标题)。
问题是我想要插入的html使用knockoutjs绑定。敲除似乎没有这样初始化绑定。
有没有办法解决这个问题?
这是我想要插入的html的一部分。这几乎是表格的一些自定义过滤器函数的下拉列表。
'< li>< a data-bind =click:Filter(\'Severity 1 \', 2)>严重性1< / a>< / li>'
你必须在插入动态HTML元素后调用这个函数
ko.applyBindings(viewModel,elementContainingDynamicContent)
示例这里 http://jsfiddle.net/rniemeyer/FCN5p /
I'm using JQuery DataTables for all my tables because of all the nice built-in features, but it seems the only way to customize the table layout is to set the "sDom" option attribute for the DataTable and use something like $("div.SOMECLASS").html(HTML_HERE)
to insert the customized html into the table. (FYI, i'm just trying to customize the header).
The problem is I want the inserted html to use knockoutjs binding. Knockout doesn't seem to initialize the binding this way.
Is there a way to work around this?
This is part of the html that I want to insert. It's pretty much a drop down list of some custom filter functions for the table.
'<li><a data-bind="click: Filter(\'Severity 1\', 2)">Severity 1</a></li>'
You have to call this function after insert dynamic HTML element
ko.applyBindings(viewModel, elementContainingDynamicContent)
Example here http://jsfiddle.net/rniemeyer/FCN5p/
这篇关于获取动态插入的HTML以与knockoutjs一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!