AutoComplete-devbridge:根据其他自动完成字段的更改更新参数 [英] AutoComplete-devbridge: update params on change from other autocomplete field
问题描述
我当前正在使用此插件:
I'm currently using this plugin:
https://github.com/devbridge/jQuery-Autocomplete
我想要的是,当我从 name 文本字段中选择一个选项时,我可以获取该值并将其作为参数放在 address 文本字段中,仅在该地址中存在名称的情况下,地址字段中的选项才受到限制.
What I want is that when I selected an option from the name text field I can get that value and put it as a parameter on the address text field where the options in the address field is limited only where name exist in that address.
当我从地址字段中选择一个选项时,名称字段中的选项也仅限于居住在该地址上的人的名字.
And same goes when I selected an option from the address field the options in the name field is limited only to names of persons who lives on that address.
这是我的代码:
$(document).ready(function(){
var name = '';
var add = '';
$('#name').change(function() {
name = $('#name').val();
});
$('#add').change(function() {
add = $('#add').val();
});
$('#name').devbridgeAutocomplete({
serviceUrl: 'search/name',
minChar: 2,
params: {add: add},
onSelect : function(suggestion) {
$('#name').val(suggestion.value);
}
});
$('#name').devbridgeAutocomplete({
serviceUrl: 'search/address',
minChar: 2,
params: {name: name},
onSelect : function(suggestion) {
$('#name').val(suggestion.value);
}
});
});
我不知道为什么它不起作用,是对还是错?请帮忙!
I don't know why it's not working, did I do it right or am I doing it all wrong? Please help!
还有其他人有这个问题或知道解决方案吗?
Has anyone else had this problem or know of a solution?
推荐答案
由于您的变量是字符串,因此它们将作为值而不是引用进行传递.当"#add"中的数据更改时,您需要更新"#name"输入自动完成实例上的参数:
Because your variables are strings, they are passed as values and not a reference. When data in the "#add" changes you need to update parameters on "#name" input autocomplete instance:
$('#add').change(function() {
var add = $('#add').val();
$('#name').devbridgeAutocomplete().setOptions({
params: { add: add }
});
});
这篇关于AutoComplete-devbridge:根据其他自动完成字段的更改更新参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!