我正在尝试使用 jquery ui 库在 Rails 中执行自动完成功能。但是我不断收到语法错误“语法错误:保留字“函数”在线...”
这是我的 Lesson.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;
}
});
});
我在网上读到可以用 -> 替换函数一词
我这样做了,我停止接收函数错误,但随后我收到其他语法错误,例如“语法错误:在线保留字“var”...”
难道我做错了什么?
只有第一行是coffeescript;剩下的就是普通的javascript。
尝试使用这个转换器:
http://js2coffee.org/ http://js2coffee.org/
$(function() {});
变成$ ->
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)