簡體   English   中英

從HTML類中訪問Ruby變量並在JS函數中使用它

[英]Accessing a Ruby Variable from Inside of an HTML class and Using it In a JS Function

我正在嘗試從我的HTML訪問ruby“variablename”變量:

<% array.each_with_index do |variablename, i| %>
<span class="classname">
    <a ng-href="/variablename/<%= variablename.gsub(' ', '').strip %>"> <%=variablename.strip %> </a>
</span>

在JS工具提示構造函數中:

$('.classname').ready(function(element) {
    Tooltipconstructor.create('.classname', {
      ajax: {
        type: "GET",
        dataType: "JSON",
        url: /api/etc/{} // Where I want to access the HTML/Ruby Variable
     etc..........

我該如何訪問這個變量? 謝謝!

您也可以從值a文:

$('.classname').ready(function(element) {
  var path = $('.classname > a').text()
  Tooltipconstructor.create('.classname', {
    ajax: {
      type: "GET",
      dataType: "JSON",
      url: /api/etc/+path // Where I want to access the HTML/Ruby Variable
   etc..........

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM