2014-06-19 2 views
0

나는 네 스티드 (nested_attributes)의 입력 상자가있는 레일스에서 ​​편집 뷰를 가지고 있습니다.javascript의 nested_attributes에서 반환 한 ID

<div class="form-group"> 
    <%= f.fields_for :item_prices, :class => "col-sm-2" do |ff|%> 
     <%= ff.hidden_field :store_id %> 
      <div class="col-sm-8 input_cc_size"> 
       <label><%= ff.object.store.name %></label> 
       <%= ff.text_field :regular_price, :class => "form-control input_cc_size_nested", :value => (number_with_precision(ff.object.regular_price, :precision => 2)) %> 
      </div> 
    <% end %> 
</div> 

동적으로 자바 스크립트에서 첫 번째 상자에 값을 입력하면 나머지는이 값을 사용합니다. 이 참조를 찾았습니다. Jquery: Mirror one text input to another 저는 자바 스크립트에서 그런 작업을하려고합니다. 중첩 된 특성의 ID를 javascript로 반환하고이를 통해 반복 할 수 있습니까? 내가

$('#item_item_prices_attributes_0_store_id').bind('keypress blur', function() { 
    $('#item_item_prices_attributes_1_store_id').val($(this).val()); 
    $('#item_item_prices_attributes_2_store_id').val($(this).val()); 
}); 

처럼 뭔가를 할 수 있지만 중첩 된 속성을 내가 그렇게하는 방법을 모른다 표준 식별자합니다.
미리 감사드립니다. 하지 이드 태그 이름

+0

템플릿 만이 아닌 실제 HTML을 보여줍니다. –

답변

0

@AlexAtNet 답변을 주셔서 감사합니다.

내가 한 것은 원하는 ID를 통해 for 루프를 반복하는 것이 었습니다. 또한 폼에 숨겨진 필드를 추가하여 for 루프에 필요한 ID를 가격을 계산했습니다. 내 js는 :

0

바인딩 :

$('.form-group input:eq(0)').bind('keypress blur', function() { 
    $('.form-group input:gt(0)').val($(this).val()); 
}); 

클래스 form-group하여 소자 내 다른 모든 입력에 첫 번째의 입력 값을 복사한다.

+0

jQuery 선택기에 대해 알고 싶을 수도 있습니다. http : //api.jquery.com/category/selectors/ –

관련 문제