【发布时间】:2014-07-06 21:02:49
【问题描述】:
我正在尝试将 gauge.js 插件与我的 Rails 4 应用程序一起使用,但是当我尝试点击主页。
这是我在 application.js 中的内容:
//= require jquery
//= require gauge.min.js
这就是我的 index.html 视图中的内容:
<script>
jQuery(document).ready(function(){
var opts = {
lines: 12, // The number of lines to draw
angle: 0.15, // The length of each line
lineWidth: 0.44, // The line thickness
pointer: {
length: 0.9, // The radius of the inner circle
strokeWidth: 0.035, // The rotation offset
color: '#000000' // Fill color
},
limitMax: 'false', // If true, the pointer will not go past the end of the gauge
colorStart: '#6FADCF', // Colors
colorStop: '#8FC0DA', // just experiment with them
strokeColor: '#E0E0E0', // to see which ones work best for you
generateGradient: true
};
var target = document.getElementById('foo'); // your canvas element
var gauge = new Gauge(target).setOptions(opts); // create sexy gauge!
gauge.maxValue = 3000; // set max gauge value
gauge.animationSpeed = 32; // set animation speed (32 is default value)
gauge.set(1250); // set actual value
})
</script>
我已经搜索了这个错误,发现这是脚本以错误的顺序加载的问题,所以我想知道这是否与 Rails 4 turbolinks 有关,因为我在加载 JS 的其他部分时遇到了问题我的应用程序。
【问题讨论】:
-
我读到有人因为导入 .min.js 而不是 .js 而遇到这个问题。也许你面临同样的问题。您可以尝试导入 .js 而不是 .min 吗?
-
它的 .coffee 版本仍然存在同样的问题:Uncaught TypeError: undefined is not a function gauge.js
标签: javascript jquery ruby-on-rails ruby-on-rails-4