问题
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