1

我正在尝试创建一个包含字段的页面,该页面使用自动完成功能。第一个字段 -"ana"工作正常。第二个失败。我在控制台中看不到任何错误。提示不出现。这里的片段:

<script src="/inc/jquery-1.8.3.js"></script>
<script src="/inc/jquery-ui.js"></script>
<link href="/inc/jquery-ui.css" rel="stylesheet" type="text/css"/>

<table>
<tr>
<td>Ticker:</td><td><input type="text" name="ana" /></td>
</tr>
<tr>
<td>Cmp:   </td><td><input type="text" name="sou" /></td>
</tr>
</table>
<div id="result" style="margin-top:25px;"></div>
<script language="javascript">
$(document).ready(function() {
    ana = [ <% getAna %>];
    $("input[name='ana']").autocomplete({ source: ana });

    sou = [ <% getSou %>];
    $("input[name='sou']").autocomplete({ source: sou});

});

</script>

我切割getAnagetSou。这些作品。这里的js/html源代码:

<script language="javascript">
$(document).ready(function() {
    ana = [ "Aar  Edw"];
    $("input[name='ana']").autocomplete({ source: ana });

    sou = [ "A&A Equity Research"];
    $("input[name='sou']").autocomplete({ source: sou});

});

</script>
4

1 回答 1

1

尝试这个

    $(document).ready(function () {
        var ana = Array();

        $.ajax({
            type: "POST",
            url: "pagename.aspx/GetAna", //GetAna must be public static web method
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (data) {
                $.map(data.d, function (item) {
                    ana.push(item.name);
                })
            }
        });
        $("input[name='ana']").autocomplete({ source: ana });

        var sou = Array();
        $.ajax({
            type: "POST",
            url: "pagename.aspx/GetSou", //GetSou must be public static web method
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            success: function (data) {
                $.map(data.d, function (item) {
                    ana.push(item.name);
                })
            }
        });
        $("input[name='sou']").autocomplete({ source: sou });

    });

在后面的代码中

    [WebMethod]
    public static List<valuepair> GetAna()//example method same method for GetSou
    {
        List<valuepair> lstvaluepair = new List<valuepair>();
       // ResumeFromBAL objResumeFromBAL = new ResumeFromBAL();
       // ResumeFrom objResumeFrom = new ResumeFrom();
        DataSet ds = new DataSet();//use your code to get dynamic data

       // ds = objResumeFromBAL.GetANA();

        if (ds.Tables.Count > 0)
        {

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                lstvaluepair.Add(new valuepair() { name = item["ResumeFromName"].ToString(), value = item["ResumeFromId"].ToString() });
            }

        }
        return lstvaluepair;

    }
    public class valuepair
    {
        public string name { get; set; }
        public string value { get; set; }
    }
于 2013-08-07T10:04:38.273 回答