问题描述
我在rails项目中使用了cocoon gem,并且有两个“ link_to_add_association”,但是我需要根据按下哪个link_to来执行某些功能,将ID为“ link_1”的link_to添加到记录中表的开头,另一个在末尾添加其他值的记录,这是我的部分形式:
= form_for([@billing,@payment]) do |f|
- if @payment.errors.any?
= render partial: 'layouts/partials/errors/form_errors',locals: { errors: @payment.errors }
= f.hidden_field :billing_id,value: @billing.id
.row
.col-md-6
.form-group.row
.col-md-4
= f.label :payment,class: 'form-control-label'
.col-md-8
= f.text_field :payment,class: 'form-control text-right','data-currency-format--live': '','data-target': '#total-pay'
.col-md-6
.form-group.row
.col-md-4
= f.label :day,class: 'form-control-label'
.col-md-6
= f.text_field :day,class: 'form-control datepicker','data-startView': 'days','data-minyear': @billing.date_bill.year,'data-minmonth': @billing.date_bill.month,'data-minday': @billing.date_bill.day
.col-md-1
.links
= link_to_add_association 'add',f,:payment_details,partial: 'payment_detail_fields',:"data-association-insertion-node" => "tbody.details",:"data-association-insertion-method" => "prepend",class:"btn btn-success btn-xs",id: "link_1"
.col-md-1
.links
= link_to_add_association 'add',partial: 'payment_detail_discount_fields',:"data-association-insertion-method" => "append",id: "link_2"
.col-md-12
#payment_details
%table.tabla_personalizada
%thead
%tr
%th value_paid
%th voucher
%th accion
%th value_paid
%th value_paid
%th voucher
%th accion
%tbody.details
= f.fields_for :payment_details do |payment_detail|
= render 'payment_detail_fields',f: payment_detail
%tr
%td
%td
%td
%td
%td
%td
%td
%tr.descuentos
%td Descuento
%td Descuento
%td
%td
%td
%td
%td
.row
.col-md-12
= f.label :comments,class: 'form-control-label'
= f.text_area :comments,class: 'form-control',rows: 6
%hr
.row
.col-md-8
.form-group.row
.col-md-8
= f.submit :class => 'btn btn-primary'
- content_for :javascript do
:javascript
$(document).ready(function() {
$("#link_1").on("cocoon:after-insert",function() {
alert("element of link_1");
} )
$("#link_2").on("cocoon:after-insert",function() {
alert("element of link_2");
} )
});
$(document).ready(function() {
$("#link_1").on("cocoon:after-insert",function() {
alert("element of link_1");
} )
$("#link_2").on("cocoon:after-insert",function() {
alert("element of link_1");
} )
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)