对属性名称包含“:"的对象使用剔除(或其他特殊字符) [英] Using knockout with property names containing ":" (or other special characters)

查看:60
本文介绍了对属性名称包含“:"的对象使用剔除(或其他特殊字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用敲除数据绑定来渲染字符串=>字符串字典的编辑器.但是,当字典键包含特殊字符(例如冒号)时,我会遇到麻烦.有没有一种方法可以转义"属性名称或特殊字符,从而使剔除正确绑定?例如,以下内容无法正确绑定:

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" />

我正在使用2.1.0版的淘汰赛

I am using version 2.1.0 of knockout

推荐答案

您需要使用 $data访问当前绑定的对象,然后从此处访问

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']" />

演示 JSFiddle .

这篇关于对属性名称包含“:"的对象使用剔除(或其他特殊字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆