Coffeescript 如何传递属性";“关联插入节点”;作为一个函数,你说得对吗?

Coffeescript 如何传递属性";“关联插入节点”;作为一个函数,你说得对吗?,coffeescript,cocoon-gem,Coffeescript,Cocoon Gem,cocoon文档中的示例链接是什么 我收到一个错误“…未定义”,如果我传递一个DOM对象,我会得到“数据关联插入节点=“[object,object]” 代码: $(".add-comment").on 'cocoon:before-insert', (e, object) -> wlink = $(this).children('a') wlink .attr( "data-association-insertion-node", (link) -

cocoon文档中的示例链接是什么 我收到一个错误“…未定义”,如果我传递一个DOM对象,我会得到“数据关联插入节点=“[object,object]” 代码:

$(".add-comment").on 'cocoon:before-insert', (e, object) ->
  wlink = $(this).children('a')
  wlink
    .attr(
      "data-association-insertion-node",
      (link) ->
        link.parents('.object-name').children('.comments')
    )
更新 实际上,它没有,它只有一个嵌套,说到多个嵌套,我在另一个部分中有一个,它工作得很好,但是在插入之前我使用js中生成的ID,所以我能够将关联插入节点设置为字符串。 但在这种情况下,我没有这样的机会,所以我选择了遍历方法

所以我想说的是我不明白它是怎么工作的

function(link){
    return link.closest('.row').next('.row').find('.sub_tasks_form')
}
因为我得到

TypeError: link.parents is not a function.
 (In 'link.parents('.object-name')', 'link.parents' is undefined)`
似乎它必须被声明,但它不是,也许链接还有另一个入口点,也许它因为咖啡而不起作用

如果我通过
$(这个)
我会得到

<a data-association-insertion-method="append" 
class="add_fields" data-association="comment" 
data-associations="comments" 
data-association-insertion-template="Generated HTML" 
href="#" data-association-insertion-node="[object Object]"> add comment</a>

我想要的是通过DOM遍历,将注释发布到相对对象

附笔 非常感谢您的关注

我使用数据而不是attr,但imho是相同的nathanvda 3月30日8:38


这很重要。从attr更改为data后开始工作。

请澄清:您能再解释一下您想做什么吗?似乎在插入嵌套表单时,它包含另一个到添加关联的链接(双嵌套表单),并希望控制该嵌套表单上的插入行为,对吗?乍一看,这似乎是正确的imho(在我使用
数据
而不是
属性
中,但imho是相同的)。我更新了问题