jQuery在rails中拖放div容器

时间:2013-09-20 04:57:22

标签: jquery ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

我正在努力将我的帖子拖到类别中;我正在使用jQuery函数来实现可拖动和可放置的效果。但是,使用下面的jQuery droppable给我一个错误的轨道;

$(".display_type").droppable({
        accept: ".brand_span",
        hoverClass: "active",
        drop: function(event, props) {
          $("#display_container").load("brand_display/change",
              {drag_id: $(props.draggable).attr("id"),
               drop_id: $(this).attr("id")});
        }
  });

我收到错误消息;

SyntaxError: reserved word "function"

我知道我必须为Coffee JS改写它......我喜欢吗?

$(".display_type").droppable({
        accept: ".brand_span",
        hoverClass: "active",
        drop: -> (event, props) {
          $("#display_container").load("brand_display/change",
              {drag_id: $(props.draggable).attr("id"),
               drop_id: $(this).attr("id")});
        }
  });

1 个答案:

答案 0 :(得分:0)

通过将上述内容转换为Coffee norm来计算出来;

 $(".label").droppable
  accept: ".entry"
  hoverClass: "active"
  drop: (event, props) ->
     $("#content").load "brand_display/change",
      drag_id: $(props.draggable).attr("id")
      drop_id: $(this).attr("id")