在app rails中找不到jquery autocomplete

时间:2012-09-05 08:45:32

标签: javascript jquery ruby-on-rails autocomplete

我在rails项目上工作,我遇到了一个jquery插件的问题:autocomplete。     我尝试用多个单词实现一个搜索引擎,我在我的网页1.8.0.min.js和插件自动完成(jquery-ui-1.8.23.custom.min.js)和下面的代码中包含另一个.js也包括:

$(document).ready(function(){      
    var availableTags = [
    "ActionScript",
    "AppleScript",
    "Asp",
    "BASIC",
    "C",
    "C++",
    "Clojure",
    "COBOL",
    "ColdFusion",
    "Erlang",
    "Fortran",
    "Groovy",
    "Haskell",
    "Java",
    "JavaScript",
    "Lisp",
    "Scheme"
    ];
    function split( val ) {
    return val.split( /,\s*/ );
    }
    function extractLast( term ) {
    return split( term ).pop();
    }

    $( "#search" ).bind( "keydown", function( event ) {
    if ( event.keyCode === $.ui.keyCode.TAB &&
           $( this ).data( "autocomplete" ).menu.active ) {
           event.preventDefault();
        }
 })
     .autocomplete({
     minLength: 0,
        source: function( request, response ) {
        // delegate back to autocomplete, but extract the last term
        response( $.ui.autocomplete.filter(
        availableTags, extractLast( request.term ) ) );
        },
        focus: function() {
       // prevent value inserted on focus
       return false;
        },
        select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( "" );
        this.value = terms.join( ", " );
        return false;
        }
    });
});

在我的应用程序中,此代码不起作用,firebug给我这个警告:

    TypeError: $("#search").bind("keydown", function (event) {if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {event.preventDefault();}}).autocomplete is not a function
    TypeError: $("#search").bind("keydown", function (e) {e.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active && e.preventDefault();}).autocomplete is not a function

当我在我的应用程序之外测试它时,它的工作正常。 我在Mandriva 12.04 TLS上,使用firefox 15.0。

0 个答案:

没有答案