【问题标题】:bootstrap autocomplete not working引导自动完成不起作用
【发布时间】:2014-04-10 21:15:56
【问题描述】:

我有这个脚本 -

<script type="text/javascript">
    $(function () {
        $('#typeahead').typeahead({
            source: function (term, process) {
                var url = '@Url.Content("~/Invoice/GetNames")';
                var cname = [];
                return $.getJSON(url, { term: term }, function (data) {

                    $.each(data, function (name, id) {
                        cname.push({ id: id, name: name });
                    });
                    return process(cname);
                });
            }
        });
    })
</script>

自动完成文本框-

 <input type="text" name="names" value="" id="typeahead" data-provide="typeahead" />

我从服务器端获取所有东西。但唯一的问题是过滤 viewpage 上的数据。

如何过滤这些数据,使其自动完成。

方法-

  [HttpGet]
        public JsonResult GetNames(string term)
        {
            var names = (from u in db.Contacts
                         where u.name.Contains(term)
                         select u).ToArray();
            // A list of names to mimic results from a database
            var results = names.Select(u => new { name = u.name, id = u.Id });

            return new JsonResult()
            {
                Data = results,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

【问题讨论】:

    标签: jquery asp.net-mvc twitter-bootstrap autocomplete


    【解决方案1】:

    试试这个: &lt;form autocomplete="on"&gt;

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 2019-10-06
      • 1970-01-01
      • 2012-07-10
      相关资源
      最近更新 更多