整个列表被填充在 Ajax.autocompleter 函数中
我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了答案..实际上是一个错误。我应该将 paramName 选项添加到 Ajax.autocompleter 函数中,并且应该在控制器函数中的 $_REQUEST 方法中获取值。
现在我只得到以该字母开头的条目。
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.
Now I get only the entries starting with that alphabet.