Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 令牌输入已重构,现在不会搜索_Javascript_Ruby On Rails_Coffeescript - Fatal编程技术网

Javascript 令牌输入已重构,现在不会搜索

Javascript 令牌输入已重构,现在不会搜索,javascript,ruby-on-rails,coffeescript,Javascript,Ruby On Rails,Coffeescript,如您所见,我重构了token_输入,以便在需要时可以轻松地将其添加到多个字段中。它确实有效,它将字段更改为令牌字段,但当我搜索时,它不会做任何事情 我在咖啡里有这个脚本,所以我不确定我是否遗漏了什么。谢谢 这是工作的原始代码 $('.token_input').each -> t = $(this) t.tokenInput t.data('url'), crossDomain: false prePopulate: t.data('load')

如您所见,我重构了token_输入,以便在需要时可以轻松地将其添加到多个字段中。它确实有效,它将字段更改为令牌字段,但当我搜索时,它不会做任何事情

我在咖啡里有这个脚本,所以我不确定我是否遗漏了什么。谢谢

这是工作的原始代码

  $('.token_input').each ->
    t = $(this)
    t.tokenInput t.data('url'),
      crossDomain: false
      prePopulate: t.data('load')
      preventDuplicates: true
      minChars: 4
      theme: 'facebook'

所有的数据属性都设置好了吗?我想设置好了,我更新了我的问题。f.text_字段的选项是散列,您正在尝试添加两个:数据键。您不想要“数据url=>'…'、“数据加载”=>'…'或者:数据=>{:url=>'…',:加载=>'…}吗?我假设你真的在用是的,我忘了文本字段是散列。按老办法做,效果很好!谢谢
  $('#restaurant_cooking_style_id').tokenInput('/cooking_styles.json',
    { crossDomain: false, prePopulate: $('#restaurant_cooking_style_id').data('load'), preventDuplicates:true, theme: 'facebook', minChars: 4 }
    )


<%#= f.text_field :cooking_style_id, class: 'token_input', data: { url: '/cooking_styles.json'}, data: { load: @restaurant.cooking_styles.collect { |cooking_style| {:id => cooking_style.id, :name => cooking_style.style } } } %>