选择后Zend Autofill下拉列表

时间:2014-01-27 07:15:50

标签: javascript php jquery ajax zend-framework

从自动填充搜索字段中选择所需的值后,我一直在处理自动填充变更下拉列表的代码。问题是我的自动填充在选择值后不起作用,但Jquery执行脚本并获取id工作完美,不知道我缺少什么。这是我的代码和图片。请注意我有多个jquery脚本执行程序类型。这是我得到的错误信息 Message: Could not find row 50390

堆栈追踪:

C:\xampp\htdocs\portal-gep-2\application\modules\admin\controllers\AjaxController.php(366): Model_SicCode->getsiccode('50390'

请求参数:

array (
  'controller' => 'ajax',
  'action' => 'autofill',
  'sicid' => '50390',
  'lang' => 'en',
  'module' => 'admin',
)  

我的数据库中确实存在ID,但我的下拉列表不会更改。我怎么能这样做?

contoller

    public function autofillAction()
    {
        //get the id send via a get - the sic id
        $division= $this->getRequest()->getParam('sicid');  

        //get majorgroup name, group name and sic description
        //fill dropdowns with relevant values - new form with drop downs
        //selecting the required values same as autocomplete (don't know)
        $mdlSic = new Model_SicCode();
        $results = $mdlSic->getsiccode($division);
        foreach($results as $result)
        {
            $Division = $result->div_code;

            $mdlDivision = new Model_Division();
            $result = $mdlDivision->getSicViaDiv($division);
            $name = $result->div_desc;
            $id = $result->div_code;


            $mgrp_desc->addMultiOption($id, $name);
        }
        $mgrp_desc->setOrder(4);  

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

        $ajaxContext = $this->_helper->getHelper('AjaxContext');
        $ajaxContext->addActionContext('newfield', 'html')->initContext();

        $id = $this->_getParam('id', null);

        $this->view->field = $div_desc->__toString();   
    }


jquery

    function ajaxautofill(id) { 
            $.ajax({
            type: 'POST',
            datatype: 'JSON',
            url: '<?php echo $this->baseURL()?>/admin/ajax/autofill/sicid/' + id,


                        //data: 'division':$('#div_desc').val(),
                        //dataType: 'JSON',
                        //async: true,
                        success: function(data) 
                        {
                            //fill drop downs

                            $('#t2').append(data);
                        }
            });
      }

获取siccode

   public function getSICviaDiv($d_id)
            {
                $select = $this->select()->where('div_code = ?', $d_id);    


                    $results = $this->fetchAll($select);
                if (count($results))
                    return $results;
                else
                    return 'nothing';

}

GetsicViaDiv

public function getSicViaDiv($siccode)
        {
            $select = $this->select();
            $select->where('div_code = ?', $siccode);

            return $this->fetchAll($select);
        }

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,您已经构建了两次select对象。其次,我建议答案在这里:

$row = $this->fetchRow($select);    
if (!$row) 
{
    throw new Exception("Could not find row $id");
}

如果从RowSet返回的fetchRow对象为false,则抛出异常。今天晚上,当我拿着笔记本电脑时,我会编写一些代码。