Using knockout with property names containing “:” (or other special characters)

半世苍凉 提交于 2020-04-30 07:38:25

问题


I am using knockout data binding to render an editor for a string => string dictionary. However, I'm running into trouble when dictionary keys contain special characters such as colon. Is there a way to "escape" a property name or special character such that knockout will bind properly? For example, the following does not bind properly:

<p data-bind="text: foo::bar" />

I am using version 2.1.0 of knockout


回答1:


You need to use $data to access the currently bound object and from there the array indexer syntax to access any of its properties which are containing special characters:

<p data-bind="text: $data['foo::bar']" />

Demo JSFiddle.



来源:https://stackoverflow.com/questions/23746342/using-knockout-with-property-names-containing-or-other-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!