admin管理员组文章数量:1415475
I'm using knockout to dynamically loading content into parts of the page, using the HTML binding.
the problem is that the html I want to bind has to do call a function onclick and I need the information about the target and the data that knockout easily send.
something like this:
myFunction($parent, $data)
HTML:
<table>
<tbody data-bind="foreach: rows" >
<tr>
<td data-bind="html: rowValue">this will be a link</td>
</tr>
</tbody>
</table>
Later I set the value to be a link with a knockout binding inside:
rowValue("<a href='#' data-bind=click:alert('hello')" + result.Data + "</a>");
Please check the fiddle here to see the full working code.
You can see the difference between the 2 lines I wrote, if I do a javascript onclick it works, but obviously ko is missing a late binding.
I've seen many questions about this but can't find one with a definitive answer.
I want to do this with KO, how can this be acplished? with templates maybe?
I'm using knockout to dynamically loading content into parts of the page, using the HTML binding.
the problem is that the html I want to bind has to do call a function onclick and I need the information about the target and the data that knockout easily send.
something like this:
myFunction($parent, $data)
HTML:
<table>
<tbody data-bind="foreach: rows" >
<tr>
<td data-bind="html: rowValue">this will be a link</td>
</tr>
</tbody>
</table>
Later I set the value to be a link with a knockout binding inside:
rowValue("<a href='#' data-bind=click:alert('hello')" + result.Data + "</a>");
Please check the fiddle here to see the full working code.
You can see the difference between the 2 lines I wrote, if I do a javascript onclick it works, but obviously ko is missing a late binding.
I've seen many questions about this but can't find one with a definitive answer.
I want to do this with KO, how can this be acplished? with templates maybe?
Share Improve this question edited Jul 8, 2013 at 10:59 Athari 34.3k17 gold badges110 silver badges152 bronze badges asked Jul 8, 2013 at 9:06 Maurizio In denmarkMaurizio In denmark 4,2842 gold badges32 silver badges66 bronze badges2 Answers
Reset to default 3KO applies bindings when you call ko.applyBindings. So if you modify the dom after applyBindings has been called. KO won't be aware of the new dom element.
You can use template this way :
<table>
<tbody data-bind="foreach: sitesTable.rows" >
<tr data-bind="foreach: row">
<td data-bind="template: 'myTemplate' "></td>
</tr>
</tbody>
</table>
<br/>
<a href="#" onclick="getNewData()"> click here </a>
<script id="myTemplate" type="text/html">
<a href='#' data-bind="html: cellValue, click: openAlert"> click </a>
</script>
edit by Maurizio. Use this fiddle as the other linkseems to be broken: See fiddle
You can roll your own version of the html:
binding that evaluates any bindings in the HTML that you bind... if you get me.
E.g. see https://stackoverflow./a/20821523/188926
Usage:
<td data-bind="bindHTML: rowValue"></td>
本文标签: javascriptknockout html binding with another binding insideStack Overflow
版权声明:本文标题:javascript - knockout html binding with another binding inside - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745230693a2648810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论