0

我将以下 JavaScript 嵌入到 Rails 视图中,但它仅在通过 URL 直接访问地址或在不通过链接访问时刷新页面时才加载。例如,点击链接<a href="localhost:3000/searches/50">不会显示表格(但会显示页面的其余部分),但会刷新页面或localhost:3000/searches/50在地址栏中输入。

<script  type="text/javascript" charset="UTF-8">
google.load('visualization', '1', {packages:['table']});
  google.setOnLoadCallback(drawTable);
  function drawTable() {
   var data = new google.visualization.DataTable();
    data.addColumn('number', '#');
    data.addColumn('string', 'Actions');
    data.addRows([
        <% @items.each do |item| %>
            [ 
            <%= item.id.to_s %>, 
            '<%= link_to edit_item_path(item) do %>
               <i class="icon-edit"></i>
             <% end %>'
            ],
        <% end %>           
    ]);         
    var table = new google.visualization.Table(document.getElementById('item-results'));
      table.draw(data, {allowHtml: true});      
   } 
</script>

<div id="item-results"></div>
4

1 回答 1

0

Could be Turbolinks is interfering with the javascript. Try to turn it off and see what happens.

于 2013-09-09T20:03:36.770 回答