jquery autocomplete的返回数据问题

luofuxian 2009-07-03 02:25:49
多列输出:
下面这种可以显示正常,达到2列输出,选中了一行后,可以把值填到textbox中:

var emails = [
{ name: "Peter Pan", to: "peter@pan.de" },
{ name: "Molly", to: "molly@yahoo.com" },
{ name: "Forneria Marconi", to: "live@japan.jp" },
{ name: "Master <em>Sync</em>", to: "205bw@samsung.com" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "g15@logitech.com" },
{ name: "Don Corleone", to: "don@vegas.com" },
{ name: "Mc Chick", to: "info@donalds.org" },
{ name: "Donnie Darko", to: "dd@timeshift.info" },
{ name: "Quake The Net", to: "webmaster@quakenet.org" },
{ name: "Dr. Write", to: "write@writable.com" }
];
$("#autocomplete").autocomplete(emails, {
minChars: 0,
max:15,
width: 200,
scroll: false,
scrollHeight: 500,
formatItem: function(data, i, total) {
return "<div style='float:left'>"+data.name+data.to+"</div>"
},
formatMatch: function(data, i, total) {
return data.name;
},
formatResult: function(data, value) {
return data.name;
}
}).result(function(event, data, formatted) {
$("#twoColum_abbr").val(data.to);
});

但是换成aspx输出的时候就不行了:

$("#autocomplete").autocomplete("data.aspx", {
minChars: 0,
max:15,
width: 200,
scroll: false,
scrollHeight: 500,
formatItem: function(data, i, total) {
return "<div style='float:left'>"+data.name+data.to+"</div>"
},
formatMatch: function(data, i, total) {
return data.name;
},
formatResult: function(data, value) {
return data.name;
}
}).result(function(event, data, formatted) {
$("#twoColum_abbr").val(data.to);
});

data.aspx的 Codebehind:该aspx输出到页面上的时候数据格式和emails 的数据格式是一样的,但是用这个作为数据源的时候
却总是全部输出。
问题所在 :我的问题基本和这位兄弟是一样的:http://www.javaeye.com/problems/17478

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Clear();
Response.Charset = "utf-8";
Response.Buffer = true;
this.EnableViewState = false;
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "text/plain";
Response.Write(GetLikeUserName());
Response.Flush();
Response.Close();
Response.End();
}
}
private string GetLikeUserName()
{
string[] str ={ "January", "Ceshi", "jQuery", "josn", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
StringBuilder sbstr = new StringBuilder();
sbstr.Append("[");
for (int i = 0; i < str.Length; i++)
{
if (i == str.Length - 1)
{
sbstr.Append("{name:'" + str[i] + "',to:'最后中文测试" + i + "'}");
}
else
{
sbstr.Append("{name:'" + str[i] + "',to:'中文测试" + i + Request.QueryString["q"] + "'},");
}
}
sbstr.Append("]");

return sbstr.ToString();
}

顶的都有分,解决问题的重分酬谢,不够的话我加。谢谢了!比较急。
...全文
3257 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
green_hunter 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 lvelvis 的回复:]
引用 6 楼 luofuxian 的回复:
引用 5 楼 eugenepada 的回复:
JScript code
$("#autocomplete").autocomplete("data.aspx", {
minChars: 0,
max:15,
width: 200,
scroll: false,
scrollHeight: 500,
//需要把data转换成json数据格……
[/Quote]

我也遇到这个问题,第一个值没有进行过滤,请问你是怎么解决的?
xueyong4712816 2011-07-05
  • 打赏
  • 举报
回复
谢谢5楼
luckyr1 2011-01-17
  • 打赏
  • 举报
回复
果然有高手存在,哈哈哈
LvElvis 2011-01-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 luofuxian 的回复:]
引用 5 楼 eugenepada 的回复:
JScript code
$("#autocomplete").autocomplete("data.aspx", {
minChars: 0,
max:15,
width: 200,
scroll: false,
scrollHeight: 500,
//需要把data转换成json数据格式
parse: function(data……
[/Quote]
你或许会发现,当你输入第一个值的时候,插件并没有进行过滤,只是把数据加载出来。我现在就是遇到这个问题。第一个输入的值并没有进行过滤
toe999 2010-04-16
  • 打赏
  • 举报
回复
谢谢,看看对自己有没有帮助。
messiah_huang 2009-10-28
  • 打赏
  • 举报
回复
找了很久,太感谢了
wjpop3 2009-08-07
  • 打赏
  • 举报
回复
正是我需要的
wjpop3 2009-08-07
  • 打赏
  • 举报
回复
ssss
luofuxian 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 eugenepada 的回复:]
JScript code
$("#autocomplete").autocomplete("data.aspx", {
minChars: 0,
max:15,
width: 200,
scroll: false,
scrollHeight: 500,
//需要把data转换成json数据格式
parse: function(data) {
return $.map(eval(data), function(row) {
return …
[/Quote]
可以了,呵呵 谢谢!
eugenepada 2009-07-03
  • 打赏
  • 举报
回复

$("#autocomplete").autocomplete("data.aspx", {
minChars: 0,
max:15,
width: 200,
scroll: false,
scrollHeight: 500,
//需要把data转换成json数据格式
parse: function(data) {
return $.map(eval(data), function(row) {
return {
data: row,
value: row.name,
result: row.name + " <" + row.to + ">"
}
});
},
formatItem: function(data, i, total) {
return "<div style='float:left'>"+data.name+data.to+"</div>"
},
formatMatch: function(data, i, total) {
return data.name;
},
formatResult: function(data, value) {
return data.name;
}
}).result(function(event, data, formatted) {
$("#twoColum_abbr").val(data.to);
});

luofuxian 2009-07-03
  • 打赏
  • 举报
回复
麻烦看下他的:http://www.javaeye.com/problems/17478 和我的情况类似,他的一列的,我的是多列的。
luofuxian 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 natineprince 的回复:]
data.aspx没做过滤.

When a user starts typing in the input box, the autocompleter will request autocomplete_ajax.cfm with a GET parameter named q that contains the current value of the input box. Let's assume that the user has typed "sp" (without quotes). Autocomplete will then request autocomplete_ajax.cfm?q=sp.

意思是,当用户有输入的时候,autocomplete就会做一个这样的事情.
将第一个参数用GET…
[/Quote]
可能我讲的不是很清楚,我试指返回数据为什么不是跟emials的数据格式一样,emials是json的数据格式可以用的,但是我的
aspx返回的也是这样的格式,可它不认,为什么?
你看返回的数据全放再一个行里面了:
[{name:'January',to:'中文测试0z'},{name:'Ceshi',to:'中文测试1z'},{name:'jQuery',to:'中文测试2z'},{name:'josn',to:'中文测试3z'},{name:'February',to:'中文测试4z'},{name:'March',to:'中文测试5z'},{name:'April',to:'中文测试6z'},{name:'May',to:'中文测试7z'},{name:'June',to:'中文测试8z'},{name:'July',to:'中文测试9z'},{name:'August',to:'中文测试10z'},{name:'September',to:'中文测试11z'},{name:'October',to:'中文测试12z'},{name:'November',to:'中文测试13z'},{name:'December',to:'最后中文测试14'}]
monexus 2009-07-03
  • 打赏
  • 举报
回复
支持1L,帮顶
natineprince 2009-07-03
  • 打赏
  • 举报
回复
data.aspx没做过滤.

When a user starts typing in the input box, the autocompleter will request autocomplete_ajax.cfm with a GET parameter named q that contains the current value of the input box. Let's assume that the user has typed "sp" (without quotes). Autocomplete will then request autocomplete_ajax.cfm?q=sp.

意思是,当用户有输入的时候,autocomplete就会做一个这样的事情.
将第一个参数用GET的方式获取数据.而且将用户输入作为参数传递.
所以你的ASPX中要用request.getParameter("p")来做条件过滤.

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧