Mootools 自动建议定制

发布于 2024-12-24 21:01:25 字数 2056 浏览 2 评论 0原文

我的网站之一为 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 技术交流群。

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

发布评论

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

评论(1

后eg是否自 2024-12-31 21:01:25

它看起来

'postData':{'country':$('country'.get('value'))},

应该是:

'postData':{'country':$('country').get('value')},

此外,每次 $('country') 更改时都应该更新“建议状态”,不是吗?如果是这样,您不应该在选择countryAutocomplete时执行stateAutocomplete请求吗?

看起来

$('country').value = country =  selected.retrieve('autocompleteChoice').id;

这样会更好:

$('country')set("value",selected.retrieve('autocompleteChoice').id);

干杯!

it looks like

'postData':{'country':$('country'.get('value'))},

should be :

'postData':{'country':$('country').get('value')},

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

$('country').value = country =  selected.retrieve('autocompleteChoice').id;

looks like it would be better like this :

$('country')set("value",selected.retrieve('autocompleteChoice').id);

Cheers !

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