Mootools 自动建议定制
我的网站之一为 autosuggest Country 扩展了 http://digitarald.de/project/autocompleter/ 插件,州和市。
例如: 州应该有两个输入,例如搜索文本和国家/地区代码。
从上述插件的文档中,该插件用于
'postVar' : 'text',
'postData':{'country':$('country'.get('value'))},
传递多个参数。
这里 $('country')
根据第一个建议设置国家/地区代码。现在的问题是我无法发送 country
作为输入,因为它是通过动态 javascript 调用设置的。如何解决问题。
尝试如下
var countryAutocomplete = new Autocompleter.Request.JSON('countrySearch', 'www.example.com/country', {
'postVar' : 'text',
'minLength': 1,
'injectChoice': function(areas){
var choice = new Element('li', {'class': 'autocompleter-choices1', 'id':areas.label});
new Element('div', {'html': this.markQueryValue(areas.label),'class': 'autocompleter-choice1'}).inject(choice);
this.addChoiceEvents(choice).inject(this.choices);
choice.store('autocompleteChoice', areas);
}
});
//set the selected value in a hidden field
countryAutocomplete.addEvent('onSelection', function(element, selected, value, input) {
$('country').value = country = selected.retrieve('autocompleteChoice').id;
});
// suggets states
var stateAutocomplete = new Autocompleter.Request.JSON('stateTxt', 'www.example.com/state', {
'postVar' : 'text',
'postData':{'postData':{'country':$('country'.get('value'))},},
'minLength': 3,
'injectChoice': function(areas){
var choice = new Element('li', {'class': 'autocompleter-choices1', 'id':areas.label});
new Element('div', {'html': this.markQueryValue(areas.label),'class': 'autocompleter-choice1'}).inject(choice);
this.addChoiceEvents(choice).inject(this.choices);
choice.store('autocompleteChoice', areas);
}
});
任何帮助将不胜感激。
谢谢
One of my website extending http://digitarald.de/project/autocompleter/ plugin for autosuggest Country, State and City.
Eg:
State should have two input like search text and country code.
From the documentation of the above plugin which using
'postVar' : 'text',
'postData':{'country':$('country'.get('value'))},
for passing multiple argument.
Here $('country')
sets country code from the first suggestion. Now the problem is I can't send country
as input because its sets from dynamic javascript call. How to solve the issue.
Tried as follows
var countryAutocomplete = new Autocompleter.Request.JSON('countrySearch', 'www.example.com/country', {
'postVar' : 'text',
'minLength': 1,
'injectChoice': function(areas){
var choice = new Element('li', {'class': 'autocompleter-choices1', 'id':areas.label});
new Element('div', {'html': this.markQueryValue(areas.label),'class': 'autocompleter-choice1'}).inject(choice);
this.addChoiceEvents(choice).inject(this.choices);
choice.store('autocompleteChoice', areas);
}
});
//set the selected value in a hidden field
countryAutocomplete.addEvent('onSelection', function(element, selected, value, input) {
$('country').value = country = selected.retrieve('autocompleteChoice').id;
});
// suggets states
var stateAutocomplete = new Autocompleter.Request.JSON('stateTxt', 'www.example.com/state', {
'postVar' : 'text',
'postData':{'postData':{'country':$('country'.get('value'))},},
'minLength': 3,
'injectChoice': function(areas){
var choice = new Element('li', {'class': 'autocompleter-choices1', 'id':areas.label});
new Element('div', {'html': this.markQueryValue(areas.label),'class': 'autocompleter-choice1'}).inject(choice);
this.addChoiceEvents(choice).inject(this.choices);
choice.store('autocompleteChoice', areas);
}
});
Any help will be appreciate.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它看起来
应该是:
此外,每次 $('country') 更改时都应该更新“建议状态”,不是吗?如果是这样,您不应该在选择countryAutocomplete时执行stateAutocomplete请求吗?
看起来
这样会更好:
干杯!
it looks like
should be :
Also the "suggets states" should be updated each time the $('country') changes no ? If so, shouldn't you do the stateAutocomplete request on Selection of the countryAutocomplete ?
And
looks like it would be better like this :
Cheers !