在我的 Rails 应用程序中,我通过发送 ajax 请求来加载撰写邮件表单
我的 compose.js 文件的代码是
$('#main').html("<%= j render :partial =>"smails/form" %>");
现在在我的撰写表单中,我使用 jquery 自动完成插件实现了一个自动完成字段,当我在没有 ajax 的情况下加载表单时工作正常。我认为这是因为我正在使用document.ready,但我不知道如何使用其他任何东西。
我的 autocomlete.js.coffee 文件的代码
$(document).ready ->
split = (val) ->
val.split /,\s*/
extractLast = (term) ->
split(term).pop()
$('#smail_receiver').autocomplete
source: "/autocomplete/users"
search: ->
term = extractLast(@value)
false if term.length < 2
focus: ->
false
select: (event,ui) ->
terms = split(@value)
terms.pop()
terms.push ui.item.value
terms.push ""
@value = terms.join(",")
false
我也试过document.on