我试图触发一个更改事件后,自动complete.this更改事件将加载一个文本框与相应的名称自动完成选定的id。自动完成事件运行良好,但更改事件没有响应。
<script>
$('#CustomerSupplyId').autocomplete({
source: function (request, response) {
$.ajax({
type: "GET",
url: "/Purchase/GetSuggestion",
data: { text: request.term },
success: function (data) {
response($.map(data, function (profile) {
return { label: profile.CustomerSupplyNm, value: profile.CustomerSupplyId, id: profile.CustomerSupplyId }
}
))
},
change: function (data) {
response($.map(data, function (profile) {
$("#textbox").val(profile.CustomerSupplyNm);
}))
}
})
}
});
</script>我在这里做错了什么或者我应该做什么?如果我像这样做成功的方法
success: function (data) {
response($.map(data, function (profile) {
return { label: profile.CustomerSupplyNm, value: profile.CustomerSupplyId, id: profile.CustomerSupplyId },
$("#textbox").val(profile.CustomerSupplyNm)
}
))
}“测试框”已经加载,但是自动完成的建议是despaired.But,“textbox”值是针对我不想要的每一个击键而更改的。
发布于 2018-06-14 07:30:25
返回之前,在响应的回调中设置textbox值
$('#CustomerSupplyId').autocomplete({
source: function (request, response) {
$.ajax({
type: "GET",
url: "/Purchase/GetSuggestion",
data: { text: request.term },
success: function (data) {
response($.map(data, function (profile) {
$("#textbox").val(profile.CustomerSupplyNm);
return { label: profile.CustomerSupplyNm, value: profile.CustomerSupplyId, id: profile.CustomerSupplyId }
}))
}
})
}
});发布于 2018-06-14 06:02:52
jquery的.ajax()方法没有change属性,
检查docs 这里。
在ajax调用完成后,您应该侦听事件,例如:
$.ajax({
type: "GET",
url: "/Purchase/GetSuggestion",
data: { text: request.term },
success: function (data) {
response($.map(data, function (profile) {
return { label: profile.CustomerSupplyNm, value: profile.CustomerSupplyId, id: profile.CustomerSupplyId }
}
))
},
complete: function (data) {
do your dom manipulation here
}
})发布于 2018-06-14 06:04:45
jQuery ajax没有属性更改。因此,添加change属性没有帮助。
我觉得你想做的是这样的事。
...
.autocomplete({
source: {
...
}
change: {
// Do something ...
}
})
...https://stackoverflow.com/questions/50850364
复制相似问题