在Foundation按钮id中插入唯一ID

时间:2016-11-28 20:54:20

标签: ruby-on-rails zurb-foundation

我正在使用Foundation中的切换下拉窗格。这是我的代码......

<td><button class="button" type="button" data-toggle="<%= request.id %>">View</button>
        <div class="dropdown-pane" id="<%= request.id %>" data-dropdown>
        <%= request.agenda %><br/>
        <%= link_to request.event, request.event, :target => "_blank" %></div></td>

按钮没有做任何事情,我收到错误......

foundation.util.triggers.self-d40e6f5….js?b…:16 Uncaught TypeError: el.data(...).split is not a function.

2 个答案:

答案 0 :(得分:2)

“id”必须是有效的html ID,其中应包含字符而不仅仅是数字。 (见What are valid values for the id attribute in HTML?)。来自rails的典型id只是一个数字...在id前面添加描述性字符串应解决此问题。 E.g。

<td><button class="button" type="button" data-toggle="request-<%= request.id %>">View</button>
    <div class="dropdown-pane" id="request-<%= request.id %>" data-dropdown>
    <%= request.agenda %><br/>
    <%= link_to request.event, request.event, :target => "_blank" %></div></td>

答案 1 :(得分:0)

不确定原因,但这对我有用:

<td><button class="button" type="button" data-toggle=<%="dropdown-pane#{request.id}"%>>View</button>
            <div class="dropdown-pane" id=<%="dropdown-pane#{request.id}"%> data-dropdown>
            <%= request.agenda %><br/>
            <%= link_to request.event, request.event, :target => "_blank" %></div></td>

似乎想要数据切换和id属性的#{} ruby​​语法。