render:partial在escape_javascript上仅生成一次 [英] render :partial generates only one time on escape_javascript

查看:89
本文介绍了render:partial在escape_javascript上仅生成一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

render:partial在escape_javascript上仅生成一次

render :partial generates only one time on escape_javascript

例如

<script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
        $("#addPerson").click(function(){
           $("#user tr:last ").after("<%= escape_javascript(render :partial => 'user_item', :locals =>{:user_item => User.new}) %>");
                   return false;
        });  

    });
</script>

并且我已经在user_item局部文件中检查了object_id,它显示相同的object_id,直到保存并仅保存最后一个项目.

and I have checked object_id in the user_item partial file it is showing same object_id until saving and saves only last item.

<%= user_item.object_id %>

结果

12354

每次. 请帮我解决这个问题.

every time. Please help me to solve this problem.

推荐答案

这是因为部分渲染仅渲染一次.

it's because the partial is render only once time.

HTML文件仅生成一次.当您调用此Javascript函数时,它不会调用Partial,因为它已经生成了.

The HTML file is generate only one time. When you call this Javascript function, it don't call the partial because it's already generate.

如果您每次都想要新一代.您需要使用user_id进行服务器调用并获取HTML.

If you want a new generation each time. You need made a server call with your user_id and get the HTML in return.

这篇关于render:partial在escape_javascript上仅生成一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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