Sas*_*sha 8 jquery autocomplete ruby-on-rails coffeescript
我正在尝试使用jquery ui库在rails中执行自动完成功能.但是我继续得到语法错误"语法错误:保留字"功能"在线......"
这是我的lessons.js.coffee文件
jQuery ->
$(function() {
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#lesson_tag_name" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
source: $('#lesson_tag_name').data('autocomplete-source')
},
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
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;
}
});
});
Run Code Online (Sandbox Code Playgroud)
我在网上读到了我可以用 - >我做了那个替换单词功能,我停止接收函数错误,但后来我得到其他语法错误,如"语法错误:保留字"var"在线..."
难道我做错了什么?