我通过像这样附加它的 uuid 来发送名称
hari_8053dd70-da5a-11e2-90a9-8d5bc608c78f
我在 autoCompletefb 中显示这个。当在下拉列表中选择一个值时,我将使用“_”拆分字符串并获取 uuid。但我的问题是整个字符串显示在下拉列表中。如何仅在下拉列表中显示名称,但仍然能够在选择时获取整个字符串?请帮忙
我的代码
jQuery.fn.autoCompletefb = function(options)
{
var tmp = this;
var settings =
{
ul : '',
urlLookup : [""],
acOptions : {},
foundClass : ".acfb-data",
inputClass : ".acfb-input"
}
if(options) jQuery.extend(settings, options);
var acfb =
{
params : settings,
getData : function()
{
var result = '';
$(settings.foundClass,tmp).each(function(i)
{
if (i>0)result+=',';
result += $('span',this).html();
});
return result;
},
clearData : function()
{
$(settings.foundClass,tmp).remove();
$(settings.inputClass,tmp).focus();
return tmp.acfb;
},
removeFind : function(o){
$(o).unbind('click').parent().remove();
$(settings.inputClass,tmp).focus();
return tmp.acfb;
}
}
$(settings.foundClass+" img.p").click(function(){
acfb.removeFind(this);
});
$(settings.inputClass,tmp).autocomplete(settings.urlLookup,settings.acOptions);
i = 0;
$(settings.inputClass,tmp).result(function(e,d,f){
var f = settings.foundClass.replace(/\./,'');
var img_path = $('#hiddenurl').val() +'images/';
var split_array = d[0].split('_');
var v = '<li class="'+f+'"><span> <input type="hidden" name="symptoms[]" value="'+split_array[1]+'">'+split_array[0]+'</span> <img class="p" src="'+img_path+'delete.gif"/></li>';
var x = $(settings.inputClass,tmp).before(v);
$('.p',x[0].previousSibling).click(function(){
acfb.removeFind(this);
});
$(settings.inputClass,tmp).val('').focus();
});
$(settings.inputClass,tmp).focus();
return acfb;
}
$(document).ready(function() {
var acfb = $("ul.first").autoCompletefb({urlLookup:$('#hiddenurl').val() + 'index.php/Autocomplete/'});
$("#show_value1" ).click(function(){alert(acfb.getData());});
$("#clear_value1").click(function(){acfb.clearData(); });
function acfbuild(cls,url){
var ix = $("input"+cls);
ix.addClass('acfb-input').wrap('<ul class="'+cls.replace(/\./,'')+' acfb-holder"></ul>');
return $("ul"+cls).autoCompletefb({urlLookup:$('#hiddenurl').val() + 'index.php/Autocomplete/'});
}
});