Jquery移动自动完成

时间:2013-03-26 15:39:13

标签: jquery jquery-mobile

任何人都可以看到错误,操作被调用,但页面上没有显示结果可供选择。

<script>
        $(document).on("pageinit", "#pageHome", function () {
            $("#autocomplete").on("listviewbeforefilter", function (e, data) {
                var $ul = $(this),
                    $input = $(data.input),
                    value = $input.val(),
                    html = "";
                $ul.html("");
                if (value && value.length > 2) {
                    $ul.html("<li><div class='ui-loader'><span class='ui-icon ui-icon-loading'></span></div></li>");
                    $ul.listview("refresh");
                    $.ajax({
                        url: "@Url.Action("Search","Schedule")",
                        data: {
                            q: $input.val()
                        }
                    })
                        .then(function (response) {
                            $.each(response, function (i, val) {
                                html += "<li>" + val + "</li>";
                            });
                            $ul.html(html);
                            $ul.listview("refresh");
                            $ul.trigger("updatelayout");
                        });
                }
            });
        });
    </script>

<div data-role="page" id="pageHome">
 <ul id="autocomplete" data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Find a city..." data-filter-theme="d"></ul>
</div>

//搜索

public ActionResult Search(string term)
        {

            return new JsonResult
            {
                Data = _Service.FindAllByWildCard(term)
                    .Select(p => new { p.Name}).ToArray(),
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }

0 个答案:

没有答案