проблема с автозаполнением JQuery и Zend Framework - PullRequest
0 голосов
/ 16 августа 2010

Я пытаюсь реализовать этот учебник в моем приложении.Мне удалось заставить его работать до тех пор, пока мне не пришлось изменить контроллер представления и добавить ссылку на файл .ajax.html.

Пока мой код:

 class MenuController extends Zend_Controller_Action {

        public function init() {
            $this->_helper->ajaxContext()->addActionContext('addRecipe', 'html')->initContext();
            parent::init();
     }

              public function addRecipeAction() {
            if ($this->_helper->ajaxContext()->getCurrentContext()) {
                $this->view->words = array('leon', 'lionel', 'Lenny', 'Linda', 'Lindy');
            }

            $recipeForm = new Application_Form_Recipe();
            $recipeForm->setMethod('post');
            $recipeForm->setAction('/menu/add-recipe');
            $this->view->recipeForm = $recipeForm;
        }
        }

Файл add-recipe.ajax.phtml:

<?php
foreach ($this->words as $word) {
    echo "{$word}\n";
}
?>

Файл вида add-recipe.phtml

<?php

echo $this->headLink()->appendStylesheet('/js/jquery/css/jquery.autocomplete.css');
$this->jQuery()->enable();
$this->jQuery()->addJavascriptFile('/js/jquery/js/jquery.autocomplete.js');

?>
<script type="text/javascript">
    $(document).ready(function(){
            $('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html');
    });
</script>


<input type="text" name="username" id="username" />

По какой-то странной причине, если я заменю $('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html'); на $('#username').autocompleteArray(['Jack', 'John', 'Jason', 'Jeremy', 'jimmy', 'jean']);это работает отлично.Кажется, я не понимаю, в чем проблема.

1 Ответ

0 голосов
/ 17 августа 2010

Попробуйте:

class MenuController extends Zend_Controller_Action {

    public function addRecipeAction() {

        $words = array('leon', 'lionel', 'Lenny', 'Linda', 'Lindy');

        foreach($words as $w) echo "$w\n";

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

    }
}

Это должно работать.

Какова цель приведенного ниже кода?

$recipeForm = new Application_Form_Recipe();
$recipeForm->setMethod('post');
$recipeForm->setAction('/menu/add-recipe');
$this->view->recipeForm = $recipeForm;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...