Home > Web Front-end > JS Tutorial > Jquery Autocomplete combined with asp.net key points_javascript skills

Jquery Autocomplete combined with asp.net key points_javascript skills

WBOY
Release: 2016-05-16 18:17:46
Original
1095 people have browsed it

Problem 1: When the json string is obtained from the webserver or general application processing program (.ashx) program, it cannot be automatically recognized and is interpreted as a string type. In fact, it is not difficult to solve this problem. You only need to overload a method. Part of the code is posted below: the parts marked in red need to be paid attention to.

Copy code The code is as follows:

$("#txt").autocomplete("/ Asmx/ExecutePlan.ashx", {
extraParams:{hosid:HosID,profid:ProfID},
minChars: 0,
max: 700,
mustMatch: true,
autoFill: true ,
selectFirst: true,
scrollHeight: 220,
width:640,
scroll:true,
parse: function(data){
var obj=eval("(" data ")");
var row = [];
for(var i = 0; irow[i] = {data:obj[i], //json
value: obj[i].instName, //The value in the list
result: obj[i].instName}; //Displayed in the drop-down list
}
if(obj.length == 1)
{
// $("#hfInstID").val(obj[0].executeID);
// $("#Button1").click ();
}
return row;
} ,
formatItem: function(row, i, total) {
},
formatMatch: function(row, i, max) {
},
formatResult: function(row, i, max) {
}
});


This problem can be solved, but A new problem has arisen, that is, both formatItem and formatMatch events have failed. I don’t know how to solve it for the time being. But if you want to do some operations when filling in the results, you can still do it. That is to call this method. Please note that this is written separately from the previous $("#txt").autocomplete. The binding method written above Just like the bottom.
$("#txt").result(function(event, data, formatted) {
});
For specific parameter meanings, please refer to the official development documentation. There are only so many functions that I use at the moment, and I will add more if I encounter new ones in the future.
One additional point: The $("#txt").flushCache(); method is used to clear the autocomplete cache. Sometimes there will be cache legacy problems after changing parameters.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template