在jQuery Symdony表单中获取当前CollectionType行的元素

时间:2018-11-08 11:00:18

标签: php jquery forms symfony

我想通过jquery设置值之一。从字段中获取值并将其设置为另一个字段。有这样的东西:

$(document).on("click", "a.order_products-collection-rescue-add", function({
    $(".chosen-select").chosen();
    var $product_search = $('order_product');
    $product_search.change(
        function() {
            var single_price  = $(this).find('option.single_option:selected').attr('single_price');
            $(CURENT INDEX OF COLLECTION ROW).('input.single-price-field').val(single_price);
            console.log(this);
        }
    );
});

一切正常,但是!我如何获得“收藏行”的当前索引? 如果我单击resecue-add按钮,这将嵌入我的新表单,m getting attr single_price from selected option and in new form is second field with class single-price-field, how to get exaclly this form filed ? i don不知道如何获取此表单的索引。

1 个答案:

答案 0 :(得分:0)

$(document).on("click", "a.order_products-collection-rescue-add", function() {
  $(".chosen-select").chosen();

  var $product_search = $('select.order_product');
  $product_search.change(
    function() {
      var single_price = $(this).find('option.single_option:selected').attr('single_price');
      var product_row = $(this).parent().parent().parent();
      $(product_row).find('input.single-price-field').val(single_price);

    }
  );
});