我有一个散列“c_failures_all”,其中包含一些值,我使用jquery从变量“selVal”的下拉列表中捕获所选项目的值。那个“selVal”将作为我哈希的关键。问题是selVal是一个jquery变量,如果这样做
c_failures_all[selVal]
为#<#:0x15484300>“
引发错误”未定义的局部变量或方法`selVal' c_failures_all = {"Amount"=>[5, 4, 8, 7, 6], "Lookup"=>[10, 85, 56, 23, 10], "Advantage"=>[9, 5, 40, 12, 3]}
<script>
$("#error_error_id").on('change', function(){
//alert('f')
var selVal = $("#error_error_id").val();
if(selVal == "All" || selVal == '')
{
options.series = [{name: 'All', data: <%= c_failures_arr %>}]
}
else
{
options.series = [{name: 'D', data: <%= c_failures_all[selVal] %>}]
}
var chart = new Highcharts.Chart(options);
});
</script>
答案 0 :(得分:1)
<script>
var arrayFailures = <%= c_failures_arr.to_json %>;
$("#list").on('change', function(){
var selVal = $("#list").val();
if(selVal == "All" || selVal == '')
{
options.series = [{name: 'All', data: arrayFailures[selVal] }]
}
else
{
options.series = [{name: 'other', data: [4,7,9,6,2]}]
}
var chart = new Highcharts.Chart(options);
});
<script>
我没有测试过,告诉我它是否正常工作。