dtcyv3985 2012-07-20 08:53
浏览 66
已采纳

如何在Zend中的视图之间传递数据列表?

I have two dropdown list which is question and answer. At first the answer dropdown list is empty, after the user choose a question, then it will pass the question_id to controller to run a function to get the answer. After the controller get the result, it will pass to the correspond view. Now how can I pass the result to the index view?

the index view:

$("#id_question").change(function() {
var data = $("#id_question").val();
var dataToSend = {question: data}
var href= '<?php echo $this->baseUrl('admin/comment/checkanswer'); ?>';

    $.ajax({ type: "POST",
        url: href,
        data: dataToSend,
        success: function(response){

                //do what u wana do
        }
        });
  });`

the controller:

public function checkanswerAction()
{
    $this->_helper->layout->disableLayout();

    $question_id = $this->getRequest()->getParam('question');

    $answer_model = new Admin_Model_DbTable_Answer();
$answer = $answer_model->getAnswersByQuestionId($question_id);

$this->view->answer = $answer;
  }

the checkanswer.phtml:

foreach ($this->answer as $key => $value)
     {
         echo '<option value="'.trim($value['id_answer']).'">'. trim($value['answer_text']) .'</option>';
       }
  • 写回答

3条回答 默认 最新

  • douou9094747 2012-07-20 08:57
    关注

    The content that should be displayed in checkanswer.phtml will be affected to your javascript var response. So if you want to display this in your page, you have to make something like this :

    success: function(response){
        //do what u wana do
        $('#yourSelectID').html(response);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?