多列输出:
下面这种可以显示正常,达到2列输出,选中了一行后,可以把值填到textbox中:var emails = [
{ name: "Peter Pan", to: "[email protected]" },
{ name: "Molly", to: "[email protected]" },
{ name: "Forneria Marconi", to: "[email protected]" },
{ name: "Master <em>Sync</em>", to: "[email protected]" },
{ name: "Dr. <strong>Tech</strong> de Log", to: "[email protected]" },
{ name: "Don Corleone", to: "[email protected]" },
{ name: "Mc Chick", to: "[email protected]" },
{ name: "Donnie Darko", to: "[email protected]" },
{ name: "Quake The Net", to: "[email protected]" },
{ name: "Dr. Write", to: "[email protected]" }
];
$("#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();
    }顶的都有分,解决问题的重分酬谢,不够的话我加。谢谢了!比较急。

解决方案 »

  1.   

    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")来做条件过滤.
      

  2.   

    可能我讲的不是很清楚,我试指返回数据为什么不是跟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'}]
      

  3.   

    麻烦看下他的:http://www.javaeye.com/problems/17478  和我的情况类似,他的一列的,我的是多列的。
      

  4.   


    $("#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);
                        });