为什么我必须重新加载页面才能使点击回调正常工作?
使用 Rails 4.0.0.rc2 我想单击 table-row/table-td 而不是标准链接。table-row 有一个 css-class,并且当单击该行时,coffee-script 应该加载正确的 url。
下面显示的代码第一次运行良好并重定向到正确的目标。然后,当我单击菜单(使用 turbolink 处理)以显示原始表格时,除非我重新加载表格,否则对任何表格行的点击都不起作用。
我的haml模板看起来像这样
....
%tr{class: 'clickable-row', id: 'row-id-1'}
%td Some text
%td more text
%tr{class: 'clickable-row', id: 'row-id-2'}
%td ...
%td ...
咖啡脚本:
jQuery ->
$('.clickable-row td').click ->
target_id = $(this).parent().attr('id').replace /row-id-/,''
document.location = "/controller_xy/#{target_id}/edit"