Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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 为控制台日志格式化ruby哈希字符串_Javascript_Ruby On Rails - Fatal编程技术网

Javascript 为控制台日志格式化ruby哈希字符串

Javascript 为控制台日志格式化ruby哈希字符串,javascript,ruby-on-rails,Javascript,Ruby On Rails,我正在编写一个Rails应用程序,我有一些变量正在通过视图文件打印到浏览器控制台。特别是,我创建了一个ruby哈希,其格式如下: {string: [array], string: [array]} 例如,我可能有一个数组 {'nil': [1,2, 3], "124": [4,5], "124/125": [6]} 将其打印到浏览器控制台时,格式设置将关闭。例如,现在我有: {nil=>[1, 2, 3], "124"=>[4

我正在编写一个Rails应用程序,我有一些变量正在通过视图文件打印到浏览器控制台。特别是,我创建了一个ruby哈希,其格式如下:

{string: [array], string: [array]}
例如,我可能有一个数组

{'nil': [1,2, 3], "124": [4,5], "124/125": [6]}
将其打印到浏览器控制台时,格式设置将关闭。例如,现在我有:

{nil=>[1, 2, 3], "124"=>[4, 5], "124/217"=>[6]} 
我怎样才能去掉添加的额外字符

这是我的实际代码:

<% allBranches = Hash.new %>
<% currentBranch = Array.new %>

<% (1..@ancestry.length-1).each do |index| %>
    <% if @ancestry[index] == @ancestry[index-1] %>
        <% currentBranch.push(index) %>
    <% else %>
        <% allBranches[@ancestry[index-1]]=currentBranch %>
        <% currentBranch = Array.new %>
        <% currentBranch.push(index) %>
    <% end %>
<% end %>

<script type="text/javascript">
    console.log("allBranches: <%=allBranches%>");
</script>

console.log(“所有分支:”);

使用
html\u-safe

console.log(“所有分支:”)


如果
allbranchs
已经是一个字符串,则
to_s
部分是多余的

使用
html\u-safe

console.log(“所有分支:”)


如果
allbranchs
已经是一个字符串,则
to_s
部分是多余的

谢谢你的帮助!我得到了散列的错误“undefined method html_safe”。哦,对了,AllBranchs不是字符串。我刚刚编辑了答案,将
添加到
。谢谢你的帮助!我得到了散列的错误“undefined method html_safe”。哦,对了,AllBranchs不是字符串。我刚刚编辑了答案,将
添加到