Rails中的j函数有什么作用? [英] What does the j function in Rails do?

查看:49
本文介绍了Rails中的j函数有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚遇到一个博客,其中提到了Rails中的 j 函数.他们使用它来进行ajax样式页面更新.

I just came across a blog that mentions a j function in Rails. They were using it to do ajax style page updates.

$('#cart').html("<%=j render @cart %>");

我知道他们正在使用局部渲染来渲染 cart 部分,但是 j 的意义是什么?我发现有些文章说它将字符串转换为JavaScript可以接受的东西,但这是什么意思?

I get they are using partials to render the cart partial, but whats the point of j? I've found some articles that say it converts the string to something JavaScript will accept, but what does that mean?

推荐答案

escape_javascript(javascript)

escape_javascript(javascript)

转义JavaScript句段的回车符和单引号和双引号.

Escapes carriage returns and single and double quotes for JavaScript segments.

也可以通过别名j()获得.

Also available through the alias j().

rails文档中.

这篇关于Rails中的j函数有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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