使用knockoutjs虚拟元素即时创建html部分 [英] Use knockoutjs virtual element to create html part on the fly
问题描述
我尝试使用带有html绑定的虚拟元素来动态创建html部分,但失败了:绑定'html'不能与虚拟元素一起使用。这里是jsfiddle: http://jsfiddle.net/d3Dpp/ 。
任何人都知道是否有任何解决方法?
这是可能的。
工作示例在这里
可惜的,这需要一些重复内部挖空功能
更新
KnockoutJS 2.2.1添加了虚拟元素绑定到导出,所以它甚至可用在缩小的版本:
ko.exportSymbol( 'virtualElements.allowedBindings',ko.virtualElements.allowedBindings);
这意味着更好的html绑定解决方案是可能的 - 参见马蒂恩的答案。
I am trying to use "virtual element" with html binding to create html part on the fly but failed with message: "The binding 'html' cannot be used with virtual elements". Here is the jsfiddle: http://jsfiddle.net/d3Dpp/.
Anyone knows if there is any workaround?
Well, after some playing with knockout I see that it is possible.
Working example is here
unfortunatelly this requires duplication of some internal knockout functionality
UPDATE
KnockoutJS 2.2.1 added virtual elements binding to export, so it is available even in minified version:
ko.exportSymbol('virtualElements.allowedBindings', ko.virtualElements.allowedBindings);
It means that better solution for html binding is possible - see Martijn's answer.
这篇关于使用knockoutjs虚拟元素即时创建html部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!