整个列表被填充在 Ajax.autocompleter 函数中

发布于 2024-08-02 10:20:14 字数 1050 浏览 2 评论 0原文

我已经使用 Scriptaculous js 框架的 Ajax.autocompleter 函数实现了自动完成功能。代码正在运行,但我填充了整个列表,而不是仅填充与我指定的字母匹配的条目。 这是我的代码:

这是获取自动建议条目的 js 函数。

new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
                        "http://localhost/FormBuilder/forms/autoComplete",{});

这是自动完成框和填充条目的条目。

<input type="text" id="autocomplete" name="autocomplete_parameter"/>
     <div id="autocomplete_choices" class="autocomplete"></div>

这是表单控制器中的自动完成操作,其中获取与键入的字母相对应的用户列表。

function autoComplete()
{
    $this->set('users',$this->User->find('all',array('fields'=>array('User.id','User.name'),
                                                     'conditions'=>array('User.name LIKE' => $this->data['User']['name'].'%')
                                                    )
                                        )
    );
    $this->layout = "ajax";
}

但是假设如果我输入字母“p”,我会得到整个用户的列表,而不是显示以字母“p”开头的列表。为什么我会遇到这个问题?我哪里出错了?

I have implemented the auto complete functionality using the Ajax.autocompleter function of the Scriptaculous js framework. The code is working, but I get the entire list populated instead of populating only the entries that match with the letter I have specified.
This is my code:

This is the js function to get the auto-suggested entries.

new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
                        "http://localhost/FormBuilder/forms/autoComplete",{});

This is the auto complete box and the entries where the entries are populated.

<input type="text" id="autocomplete" name="autocomplete_parameter"/>
     <div id="autocomplete_choices" class="autocomplete"></div>

And this is the autoComplete action in the forms controller where get the list of users corresponding to the typed letter.

function autoComplete()
{
    $this->set('users',$this->User->find('all',array('fields'=>array('User.id','User.name'),
                                                     'conditions'=>array('User.name LIKE' => $this->data['User']['name'].'%')
                                                    )
                                        )
    );
    $this->layout = "ajax";
}

But suppose if I type letter 'p', I get the entire user's list instead of displaying the ones starting with the letter 'p'. Why do I get this problem? Where have I gone wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2024-08-09 10:20:14

好吧,我找到了答案..实际上是一个错误。我应该将 paramName 选项添加到 Ajax.autocompleter 函数中,并且应该在控制器函数中的 $_REQUEST 方法中获取值。

new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
                       "http://localhost/FormBuilder/forms/autoComplete",
                        {paramName:"autocomplete"});

function autoComplete()
{
   $userName=$_REQUEST['autocomplete'];
   $this->set('users',$this->User->find('all',array(
                                     'fields'=>array('User.id','User.name'),
                          'conditions'=>array('User.name LIKE' => $userName.'%'))
                                                                    )
              );
   $this->layout = "ajax";
}

现在我只得到以该字母开头的条目。

Well, I found out the answer.. Actually a mistake. I should add the paramName option to the Ajax.autocompleter function and should get the value in the $_REQUEST method in the controller function.

new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
                       "http://localhost/FormBuilder/forms/autoComplete",
                        {paramName:"autocomplete"});

function autoComplete()
{
   $userName=$_REQUEST['autocomplete'];
   $this->set('users',$this->User->find('all',array(
                                     'fields'=>array('User.id','User.name'),
                          'conditions'=>array('User.name LIKE' => $userName.'%'))
                                                                    )
              );
   $this->layout = "ajax";
}

Now I get only the entries starting with that alphabet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文