gpt4 book ai didi

jQuery 自动完成功能不适用于 Turbolinks

转载 作者:行者123 更新时间:2023-12-01 03:16:16 24 4
gpt4 key购买 nike

我正在使用 Rails 4。我的 shared.js.coffee 中的这段代码在没有 Turbolinks 的情况下工作正常:

jQuery ->
$('input.autocomplete,textarea.autocomplete').each (index, item) =>
sel = $(item)
sel.autocomplete
source: sel.data('autocomplete-source')
minLength: 1

但是当我使用Turbolinks时,它仅适用于页面刷新。浏览网站后它不起作用。

我已阅读 Rails 4, Turbolinks, and Delegated Event Handling in jQuery ,所以我知道出了什么问题,但我还不知道如何解决问题。

还有一个相关问题:如果 jQuery UI autocomplete plugin 任何人都可以明确评论吗? ——或者就此而言,一般的插件——是为了与 Turbolinks 一起工作而设计的吗?

最佳答案

使用jQuery Turbolinks .

"if you have a large codebase with lots of $(el).bind(...) Turbolinks will surprise you. Most part of your JavaScripts will stop working in usual way. It's because the nodes on which you bind events no longer exist."

用法:

# Gemfile:
gem 'jquery-turbolinks'

# JavaScript manifest file:
//= require jquery.turbolinks

也许,在某个时候,jQuery $.widget 函数将提供一个以不同方式绑定(bind)的选项,但在那之前,这是有效的。不需要对 Javascript 进行其他更改。

关于jQuery 自动完成功能不适用于 Turbolinks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15958686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com