我使用jQuery UI自動完成自動完成指定更多參數?
如果我這樣做jQuery中/ asp.net:
$("#<%= txtName.ClientID %>").livequery(function() {
$(this).autocomplete('LoadNames.ashx')
.result(function (event, data, formatted) { // data[0] : Name, data[1] :AddressID
// Set Selected email ID to hidden field
$("#<%= hdnID.ClientID %>").val(data[1]);
if (data[1] != "0") {
var url = "http://emps/NewEntry.aspx?ID=" + data[1];
window.open(url);
}
else {
}
});
});
這個偉大的工程,但我想添加更多的參數,如minChars等等等等我試試這個:
$("#<%= txtName.ClientID %>").livequery(function() {
$(this).autocomplete({source:"LoadNames.ashx", delay:100, minChars:2})
.result(function (event, data, formatted) { // data[0] : Name, data[1] :AddressID
// Set Selected email ID to hidden field
$("#<%= hdnID.ClientID %>").val(data[1]);
if (data[1] != "0") {
var url = "http://emps/NewEntry.aspx?ID=" + data[1];
window.open(url);
}
else {
}
});
});
然後這不再工作。我怎樣才能添加更多的參數,如minChars,延遲等?
從評論有人想看到.ashx文件,這是它,但沒有這個問題。它只是我想其他參數添加到自動完成:
public class LoadNames : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
DataSet ds = null;
Dictionary<long, string> lstAddresses = new Dictionary<long, string>();
ds = GetLoginNames();
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
lstAddresses.Add(Convert.ToInt64(dr["LoginID"].ToString()), dr["Login"].ToString());
}
StringBuilder builder = new StringBuilder();
foreach (KeyValuePair<long, string> item in lstAddresses)
{
builder.Append(string.Format("{0}|{1}|{2}",
item.Value,
item.Key,
Environment.NewLine));
}
context.Response.Write(builder.ToString());
}
}
public DataSet GetLoginNames()
{
SqlCommand cmdSelect = default(SqlCommand);
SqlConnection conMyData = default(SqlConnection);
SqlDataAdapter daIssues = default(SqlDataAdapter);
System.Data.DataSet ds = null;
conMyData = null;
//try and make a connection
try
{
conMyData = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["connString"]);
cmdSelect = new SqlCommand("selFullNames", conMyData);
var _with1 = cmdSelect;
_with1.CommandType = System.Data.CommandType.StoredProcedure;
//add parameters
_with1.Parameters.Add("@Inactive", SqlDbType.Int).Value = 2;
daIssues = new SqlDataAdapter();
daIssues.SelectCommand = cmdSelect;
ds = new System.Data.DataSet();
daIssues.Fill(ds);
return ds;
//catch any exceptions that might be thrown
}
catch (Exception e)
{
throw e;
//clean up and close resources
}
finally
{
conMyData.Close();
cmdSelect = null;
conMyData = null;
}
}
public bool IsReusable
{
get
{
return false;
}
}
jQuery UI的自動完成或其他一些插件? – 2013-05-02 19:28:19
是的jQuery UI自動完成。 – oJM86o 2013-05-02 19:29:29
我想你可以使用內置的'。對(',而不是'livequery'插件 - jQuery的的新版本假設 – 2013-05-02 19:31:34