2013-01-12 53 views
0

我想從某個行復制值到一個對話框形式,我打電話與jQuery的,但我無法讓它正常工作。 (編輯功能)。對話框打開但不傳遞ei_Ingredient中的值。上面的「添加成分」功能完美地起作用。下面是我的代碼,你可以看到三種方式,我迄今嘗試過...Jquery - 將值添加到對話框字段

$(document).ready(function() { 

     var _Ingredient = $('#ingHeader'), 
      _newIngredient = $('#newIngredient'), 
      _newMeasurement = $('#newMeasurement'), 
      _newAmount = $('#newAmount'), 
      allFields = $([]).add(_newIngredient).add(_newMeasurement).add(_newAmount) 
     $('#dialog-form').dialog({ 
      autoOpen: false, 
      height: 300, 
      width: 350, 
      modal: true, 
      show: "clip", 
      hide: "scale", 
      speed: "fast", 
      buttons: { 
       "Add Ingredient": function() { 
        var _row = $('#templates').find('.row-template-ExistingItem').clone(); 
        _row.find('.ei_Ingredient').val(_newIngredient.val()); 
        _row.find('.ei_Measurement').val(_newMeasurement.val()); 
        _row.find('.ei_Amount').val(_newAmount.val()); 
        _row.find('.edit').click(function() { 
         _newIngredient.val(); 
         _newMeasurement.val(_row.find('ei_Ingredient').val()); 
         _newAmount.val($('.ei_Amount').val()); 
         $('#dialog-form').dialog('open'); 
        }); 
        _row.find('.delete').click(function() { 
         _row.remove(); 
        }); 

        _Ingredient.append(_row); 
        $(this).dialog("close"); 
       }, 
       Cancel: function() { 
        $(this).dialog("close"); 
       } 
      }, 
       close: function() { 
        allFields.val(""); 
       } 
     }); 

模板:

<tr class="row-template-ExistingItem"> 
     <td><input class="ei_Ingredient" readonly="true"/></td> 
     <td><input class="ei_Measurement" readonly="true" /></td> 
     <td><input class="ei_Amount" readonly="true" /></td> 
     <td><input type="button" value="Edit" class="edit" style="width:45px;" /></td> 
     <td><input type="button" value="Delete" class="delete" style="width:45px;" /></td> 
    </tr> 

形式:

回答

0

啊,我只是明白了這一點。這是工作的線路:

_newMeasurement.val(_row.find('ei_Ingredient').val()); 

我的問題是我忘了班級名稱前的一段時間。它應該是:

_newMeasurement.val(_row.find('.ei_Ingredient').val());