jquery: this.bindings.val -有效,但它们是否会因使用这个而产生影响?请参阅下面的代码示例。有没有更好的方法?
$("#editAssignee,#assignee").autocomplete({
source: GetPersonNamesSource,
minLength: 4,
select: function (event, ui) {
}
GetPersonNamesSource = function (request, response) {
// var personName = $('#editAssignee').val();
var personName = this.bindings[0].value;
$.ajax({
type: "GET",
url: path + '/api/PersonCED/ByBEMSorName/' + personName,
data: personName,
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout: 99000, // 8000= 8seconds, 99000 = 1 Min 39 seconds
success: function (data) {
response($.map($.parseJSON(data), function (item) {
var LastFirstM = item.LastName + ', ' + item.FirstName + ' ' + item.MiddleName;
return {
value: item.BEMSID,
label: LastFirstM
//objPerson: item
}
}))
} // end success
}) // end .ajax
} // end function发布于 2015-10-11 15:11:55
访问source选项回调中的自动完成小部件的值的正确方法是通过请求参数的term属性。
例如:
var GetPersonNamesSource = function (request, response) {
var personName = request.term;
$.ajax({
type: "GET",
url: '/json',
data: personName,
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout: 99000, // 8000= 8seconds, 99000 = 1 Min 39 seconds
success: function (data) {
response($.map($.parseJSON(data), function (item) {
var LastFirstM = item.LastName + ', ' + item.FirstName + ' ' + item.MiddleName;
return {
value: item.BEMSID,
label: LastFirstM
//objPerson: item
}
}))
} // end success
}) // end .ajax
} // end function
$("#editAssignee").autocomplete({
source: GetPersonNamesSource,
minLength: 4,
select: function (event, ui) {}
});附带注意:如果不是字符串,data选项的值将转换为查询字符串。它被附加在url上,用于获取请求。因此,您可能不需要手动将其附加到url中。
https://stackoverflow.com/questions/33042167
复制相似问题