jQuery中有没有类似MooTools的替代方法?
这是MooTools代码:
var myString = "{subject} is {property_1} and {property_2}.";
var myObject = {subject: 'Jack Bauer', property_1: 'our lord', property_2: 'savior'};
myString.substitute(myObject);
jQuery有这个方法或类似的方法吗?
This is MooTools code:
var myString = "{subject} is {property_1} and {property_2}.";
var myObject = {subject: 'Jack Bauer', property_1: 'our lord', property_2: 'savior'};
myString.substitute(myObject);
Does jQuery has this method or similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,但是没有什么可以阻止您自己添加它:
No, but there's nothing preventing you from adding it yourself:
试试这个插件 https://github.com/trix/nano ,源代码只有几行
你可以使用点符号 {user.name} ,简单而强大。
Try this plugin https://github.com/trix/nano , the source is just a few lines
You can use dot notation {user.name} , just simple and powerful.
$.nano
答案让我陷入了困境,因为如果模板点符号中有任何拼写错误,它就会出错,而且它不允许所有合法字符,例如a['foo bar ']
下面是我作为$.substitute
插件的版本:The
$.nano
answer threw me for a loop because it errors if you have any typos in your template dot notation, and furthermore it doesn't allow all legal characters likea['foo bar']
so below is my version as a$.substitute
plugin:有一些插件与 .NET 中的 String.Format 方法共享类似的语法。
这个利用了 jQuery Validate 插件(常见于 CDN)。
示例:
第二个插件名为 .NET 样式字符串格式。
示例:
这些可能并不完全是您正在寻找的内容,但它们可能很有用。
There are some plugins that share a similar syntax to the String.Format method in .NET.
This one leverages the jQuery Validate plugin (commonly found on CDNs).
Example:
The second plugin is named .NET Style String Format.
Example:
These may not be exactly what you're looking for, but they may be useful.