Typeahed不适用于操作

时间:2015-07-01 12:15:04

标签: jquery typeahead.js nopcommerce

大家好!我正在尝试使用nopcommerce中的动作调用实现typeahead.js。我正在尝试使用自动完成搜索框,但失败了,所以我决定使用typeahead.But它不起作用。可能是什么问题? 有页面+脚本的代码

@model SearchBoxModel
@using Nop.Web.Models.Catalog;
@using (Html.BeginRouteForm("ProductSearch", FormMethod.Get, new { onsubmit = "return check_small_search_form()" }))
{
 <input type="text" data-provide="typeahead" id="small-searchterms" @(Model.AutoCompleteEnabled ? Html.Raw(" autocomplete=\"off\"") : null)
       value="@T("Search.SearchBox.Tooltip")" name="q" onfocus="if(this.value=='@T("Search.SearchBox.Tooltip")')this.value=''" onblur="if(this.value=='') {this.value = '@T("Search.SearchBox.Tooltip")';}" />
<script type="text/javascript">

function check_small_search_form() {
    var search_terms = $("#small-searchterms");
    if (search_terms.val() == "") {
        alert('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Search.EnterSearchTerms").Text))');
        search_terms.focus();
        return false;
    }

    return true;
}
@if (Model.AutoCompleteEnabled)
        {
            <text>

    $('#small-searchterms').typeahead({
        source: function (query, process) {
            return $.get('@Url.Action("CatalogController/ProductSearchAutoComplete")', { query: query }, function (data) {
                return process(data);
            });
        },
        select: function( event, ui ) {
        $("#small-searchterms").val(ui.item.label);
        setLocation(ui.item.producturl);
        return false;
    }
    }).data("ui-autocomplete")._renderItem = function( ul, item ) {
        var t = item.label;
        //html encode
        t = htmlEncode(t);
        return $("<li></li>")
        .data("item.autocomplete", item)
        .append("<a>@(Model.ShowProductImagesInSearchAutoComplete ? Html.Raw("<img src='\" + item.productpictureurl + \"'>") : null)" + t + "</a>")
                .appendTo(ul);
    };
   </script>
@Html.Widget("searchbox")
}

1 个答案:

答案 0 :(得分:0)

我发现为什么它不起作用!我需要删除这一行

t = htmlEncode(t);

一切正常。