Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 从HTML类内部访问Ruby变量并在JS函数中使用_Javascript_Html_Ruby_Variables_Tooltip - Fatal编程技术网

Javascript 从HTML类内部访问Ruby变量并在JS函数中使用

Javascript 从HTML类内部访问Ruby变量并在JS函数中使用,javascript,html,ruby,variables,tooltip,Javascript,Html,Ruby,Variables,Tooltip,我正在尝试从我的HTML访问ruby“variablename”变量: <% array.each_with_index do |variablename, i| %> <span class="classname"> <a ng-href="/variablename/<%= variablename.gsub(' ', '').strip %>"> <%=variablename.strip %> </a> &l

我正在尝试从我的HTML访问ruby“variablename”变量:

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

如何访问此变量?谢谢

您还可以从
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..........

您还可以从
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..........

你用的是角形的吗?该工具提示在指令中吗?使用angular,而不是在指令中。可以使用指令并将变量名作为属性值传递。是否使用angular?这是指令中的工具提示吗?使用angular,而不是在指令中。您可以使用指令并将变量名作为属性值传递。问题是我处理的是一个数组,数组的每个索引都有一个不同的“variablename”值。当我使用path解决方案时,它将数组中的每个项存储为变量,而不仅仅是我希望访问的项。但是,我要访问和使用的对象将根据用户悬停在哪个对象上而更改。最好的解决方案是在此处使用该指令。问题是我正在处理一个数组,其中数组的每个索引都有一个不同的“variablename”值。当我使用path解决方案时,它将数组中的每个项存储为变量,而不仅仅是我希望访问的项。但是,我想要访问和使用的对象将根据用户悬停在哪个对象上而改变。最好的解决方案是在这里使用该指令。