【问题标题】:Cocoon cocoon:after-insert coffee scriptCocoon 茧:插入后的咖啡脚本
【发布时间】:2013-01-24 22:30:53
【问题描述】:

我有一个使用 Cocoon 的嵌套表单。在嵌套表单中,我有一个选择菜单,我想在该菜单上调用 selected()。

通常我会在代码中包含以下内容

$('#cust_select').chosen()

但是,我需要在使用诸如

之类的东西添加嵌套字段后调用它
    $('#container').bind('cocoon:before-insert', function(e, inserted_item) {
      // ... do something
    });

但是,我无法让它工作,所以有 2 个问题

  1. 这段代码的咖啡脚本版本是什么?
  2. inserted_item 是要使用的实际代码还是应该将 item 替换为型号名称?

有什么想法吗?

迈克尔

【问题讨论】:

    标签: ruby-on-rails coffeescript jquery-chosen cocoon-gem


    【解决方案1】:

    1) CoffeeScript 版本是:

    $('#cust_select').chosen() # just the same
    
    $('#container').bind 'cocoon:before-insert', (e, inserted_item) -> 
      # ... do something with the inserted item
    

    2)inserted_item 确实是插入项:

    来自here

    要收听事件,您的 javascript 中有以下代码:

    $('#container').bind('cocoon:before-insert', function(e, inserted_item) {
       // ... do something
    });
    

    其中 e 是事件,第二个参数是插入或删除的项目。这允许您更改标记,或添加效果/动画(参见下面的示例)。

    【讨论】:

    • 非常感谢。工作了一个款待。慢慢了解咖啡脚本!
    猜你喜欢
    • 2013-01-09
    • 2012-08-26
    • 1970-01-01
    • 2023-03-24
    • 2017-12-26
    • 2011-11-08
    • 2011-06-30
    • 2013-06-10
    • 1970-01-01
    相关资源
    最近更新 更多