【问题标题】:How do you merge two jquery posts into one in coffeescript?你如何在coffeescript中将两个jquery帖子合并为一个?
【发布时间】:2016-08-15 14:31:01
【问题描述】:

我需要合并这两个对象:

{ swim_lane_id: $(this).closest('ul').data('lane-id') }

+

$(this).sortable('serialize')

放入一个可以作为 $.post 中的 [DATA] 发送的对象:

$.post($(this).data('update-url'), [DATA] );

$.merge 只给出swim_lane_id 和一个id,它是update-url 数据标签的一部分,但不给出可排序列表中的序列化数据。

我基本上需要能够在一篇文章中传递这些内容,因为 update-url 数据标签会路由到我的 Rails 应用程序中的控制器操作,并且我需要知道针对发送给它的每个更新操作正在更新哪个列表。

【问题讨论】:

    标签: javascript jquery ruby-on-rails coffeescript


    【解决方案1】:

    看起来很简单:

    $.post $(this).data('update-url'),
        swim_lane_id : $(this).closest('ul').data('lane-id')
        some_other_name : $(this).sortable('serialize')
    

    您在一个对象中传递两个属性。

    【讨论】:

    • 非常感谢!我是 JS 和 JQ 的新手,它是那些简单的问题之一,你最终挣扎的时间比你应该做的要长。
    • 不用担心。我们都去过那里。
    • 原来它通过以下方式发送参数:Parameters: {"swim_lane_id"=>"1", "cards"=>"card[]=2&card[]=3&card[]=4&card[]=5", "board_id"=>"1"} 这不太对...
    • 我不知道什么是对还是错,因为我不知道$(this).sortable('serialize') 是什么。这就是您通过 HTTP 调用传递数据的方式。
    猜你喜欢
    • 1970-01-01
    • 2011-11-24
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多