weixin_33675507 2014-04-02 22:29 采纳率: 0%
浏览 28

联合国部分渲染?

A user can assign a referral to an event from two separate lists, an old collection and new collection. Both collections are assigned to the same attribute. Because of this, whichever collection_select is rendered last is the only one that the form recognizes. Because of this, I've decided to render the second list only if the user needs it like so:

<div id="old_collection">
  <%= collection_select(stuff) %>
</div>

<div id="new_collection"></div>

<input id="render_new_collection" href="#" type="checkbox">New-Collection?      

<script>
    $j(function(){
      $j("#render_new_collection").click(function(){
        $j("#old_collection").toggle();
        $j("#new_collection").html("<%= escape_javascript(render(:partial => 'new_collection')) %>");
      });
    });
</script>

This works fine, but the way it's set up up is a dead end: the user can't change their mind and use the old collection unless they refresh the page. Is there a way to un-render the partial, leaving only the original form on the page?

  • 写回答

1条回答 默认 最新

  • weixin_33704234 2014-04-02 23:08
    关注

    You can do it by toggling between the new collection and the old collection.

    $j(function(){
      $j("#render_new_collection").change(function(){
        if($j(this).is(':checked')) {
          $j("#old_collection").hide();
          $j("#new_collection").html("<%= escape_javascript(render(:partial => 'new_collection')) %>");
        }
        else {
          $j("#old_collection").show();
          $j("#new_collection").html('');
        }
      });
    });
    

    Though this should work but we should keep the javascript code in separate javascript files.

    评论

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析