[英]Ajax autocomplete for Jquery, how to send dynamic parameters id
I am using the jquery autocomplete plugin, and I have several dynamic input, which I can not do is fill each input with the corresponding id. 我正在使用jquery自动完成插件,并且我有几个动态输入,我不能做的是用相应的id填充每个输入。 Here I show my code In my js 在这里,我在我的js中显示我的代码
<table cellpadding="3" cellspacing="1" border="0" align="middle">
<td width="100%">
<input type="text" name="resourcesIds[0]" size="107" value="${requestScope.form.resourceId}">
<span><img src="gif/b.gif" width="7" height="1"><input type="text" name="description[0]" size="107" class="description" value="${requestScope.form.description}" ></span>
<span><a href="#" id="somebutton"><img src="gif/new.gif" border="0" /></a></span>
</td>
</table>
<table id="containerResources">
</table>
In my js : 在我的js中:
var auto = {
serviceUrl: 'provide.do',
paramName: 'cmd',
dataType : "json",
transformResult: function(response) {
return {
suggestions: $.map(response, function(dataItem) {
return { value: dataItem.provideId+ " - " + dataItem.provideName, data: dataItem.provideId};
})
};
}
};
var a = $('.description').autocomplete(auto);
a.autocomplete().setOptions({onSelect: function(suggestion){
$("input[name=resourcesIds[0]").val(suggestion.data);
}});
var wrapper = $("#containerResources");
$("#somebutton").click(function(e){
e.preventDefault();
var numItems = $('.itemResource').length;
var numItemsFixed = numItems + 1;
var rowFile='<tr id="recurso_'+numItemsFixed+'" class="itemResource"><td width="100%;"><input type="text" name="resourcesIds['+numItemsFixed+']" size="107" value=""><input type="text" name="descriptions['+numItemsFixed+']" size="107" class="descriptions"/></td><td width="100px" align="center"><a href="#" class="remove_field">eliminar</a></td></tr>';
$(wrapper).append(rowFile);
var a = $('.description',wrapper).autocomplete(auto);
a.autocomplete().setOptions({onSelect: function(suggestion){
alert( $("input[name=resourcesIds["+ numItemsFixed +"]]").val(suggestion.data));
}});
This code does not fill any input with the id 此代码不使用ID填充任何输入
$("input[name=resourcesIds[0]").val(suggestion.data);
您缺少右方括号,应该是:
$("input[name=resourcesIds[0]]").val(suggestion.data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.