2012-08-07 3 views
0

db에서 가져온 ef_name 값을 설정할 수 없습니다. 단일 ID에 대해 여러 행이 있습니다.zend 설정 값 jquery ajax 응답을 통한 하위 형식 요소

양식

public function addRow() 
    { 
     $row_form = new Zend_Form(array(
      'elements' => array(
       'ef_name' => array(
        'type' => 'text' 
       ), 
      ),   
     )); 


     $new_form_index = count($this->_subForms)+1; 
     $row_form->setElementsBelongTo('diam['.$new_form_index.']'); 
     $this->addSubform($row_form, $new_form_index); 
     return $row_form; 
    } 




    public function init() { 
$this->addElement('hidden', 'id', array(
     'value' => 1 
    )); 

    for($cdr=0;$cdr<10;$cdr++) 
      $this->addRow();  
     } 

보기

<?php 
echo $this->form ; 
$this->jQuery()->enable(); 
?> 

<?php $this->jQuery()->onLoadCaptureStart(); ?> 
jQuery('#category').change(newEcat); 
<?php $this->jQuery()->onLoadCaptureEnd(); ?> 


<script><!-- 
    function newEcat() 
    { 
     var p = $("#category").val();  

    var response = $.ajax({ 

     url: "<?php echo $this->url(array('controller'=>'index', 
'action'=>'details')) ?>", 
     type: "GET",  
     data: {id: p}, 
     cache: false, 
     success: function(text){ 
      response = text; 

      $("#category").val($(text).find("select[name='category']").val()); 

      $("#ef_name").val($(text).find("select[name='ef_name']").val());  




}, 
error: function() { alert('Sorry, no family members defined.'); } 

    }); 

} 


--></script> 

컨트롤러

if ($this->getRequest()->isXmlHttpRequest()) { 

    $this->_helper->layout->disableLayout(); 
    $this->_helper->viewRenderer->setNoRender(TRUE); 

    $id = $this->_getParam(id);    
    $form->category->setValue($id);  

} 

답변

0

보기

function newEcat() 
{ 

    var p = $("#category").val(); 

    var response = $.ajax({ 

    url: "<?php echo $this->url(array('controller'=>'index', 'action'=>'details')) ?>", 
    type: "GET",  
    dataType: 'json', 
    data: {id: p}, 
    cache: false, 
    success: function(text){ 

    if(JSON.stringify(text) == '[]')   
    alert('Sorry, there are no family details for this employee.'); 


     for(var valVar=0;valVar<10;valVar++){    
     valVarinc = valVar+1; 
      $("#diam-"+valVarinc+"-ef_name").val(''); 

      } 

     for(var valVar=0;valVar<10;valVar++){    
     valVarinc = valVar+1; 
     if(text[valVar].ef_name != ''){ 
      $("#diam-"+valVarinc+"-ef_name").val(text[valVar].ef_name);    
      } 

      } 

}, 
error: function() { alert('Sorry, there are no family details for this employee.'); } 
}); 

} 

컨트롤러

if ($this->getRequest()->isXmlHttpRequest()) { 
     $id = $this->_getParam(id);       
     $form->category->setValue($id);  

}