【发布时间】:2014-11-07 15:21:49
【问题描述】:
我想为员工姓名附加一个 ID,因此我创建了一个对象而不是一个数组,但只使用名称而不是 ID 填充自动完成字段。 jQuery Autocomplete 源参数解析一个数组。我可以解析 object.element 吗?这是一些代码(需要更多只是问)。这可能吗?
$.ajax({
type: 'get',
url: 'xml/employeeList.xml',
error: function(xhr, status, error) {alert('Could Not Retrieve Name List: '+xhr+', '+status+', '+error)},
dataType: 'xml'
}).done(function(employees) {
var empList = []; // array of objects
$(employees).find('employeeList').children().each(function(index, element) {
var $elm = $(this),
first = $elm.find('first').text(),
last = $elm.find('last').text(),
lanID = $elm.find('lanID').text();
empList.push({ // obj having label and value properties.
value: lanID,
label: first+' '+last
});
});
console.log(empList);
$("#tags").autocomplete({
source: empList
});
});
用户从自动完成中选择一个名称后,我需要将对象中具有所选名称的员工 lanID 发送回 Web 服务。在此示例中,它没有将返回的 lanID 分配为 id。 id 最终看起来像这样( id="ui-id-345" )。我需要 id 是这样的(id="whatever 返回的 lan id 是")
选择名称后,它会显示 LanID 而不是名称。不是我想要的效果。我仍然希望它显示名称,但将 lanID 分配为输入或任何属性的 id。
【问题讨论】:
-
为什么你会说这是重复的,然后不提供另一个问题的链接?
标签: jquery jquery-ui object jquery-autocomplete jquery-ui-autocomplete