[英]Encoded HTML in optionsText binding of knockout js
I am trying to create a dropdown list with html encoded options in knockout js using options binding. 我正在尝试使用选项绑定在淘汰赛js中创建带有html编码选项的下拉列表。
How can i decode the text returned from the function binded to the optionsText binding. 我如何解码从绑定到optionsText绑定的函数返回的文本。
<select data-bind="options: items, optionsText: function(item){ return "decoded text"}"></select>
In general, I need a function that take a encoded html string and returns the decoded text. 通常,我需要一个函数,该函数接受编码的html字符串并返回解码的文本。
ie the function takes something like 即函数需要类似
blah blah balh <sup>TM</sup>
and return 然后返回
blah blah blah ™
等等等等™
This will not be possible. 这将是不可能的。 An
option
tag is not permitted to have other tags as content, only " Normal character data ". 一个
option
标签不允许包含其他标签作为内容,只能包含“ 普通字符数据 ”。 This does mean you can use entities, eg ™
这确实意味着您可以使用实体,例如
™
or ™
或
™
(which renders as "™"), which should work for your specific example. (呈现为“™”)(适用于您的特定示例)。
For completeness sake, for the Knockout part, if you were to try what you're after, you have two options: 为了完整起见,淘汰赛的一部分,如果你尝试之后你在做什么,你有两个选择:
foreach
binding and create your own option
elements with html
bound contents (as opposed to text
bound contents) foreach
绑定并使用html
绑定内容(而不是text
绑定内容)创建自己的option
元素 optionsAfterRender
binding to tweak the rendered option elements (thanks to @CaseyWebb for noting this option in the comments) optionsAfterRender
绑定来调整渲染的选项元素(感谢@CaseyWebb在注释中注意到此选项)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.