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条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?