gpt4 book ai didi

javascript - 将 JS 转换为 CoffeScript,缺少操作数?

转载 作者:行者123 更新时间:2023-11-28 08:40:28 24 4
gpt4 key购买 nike

我有一个 HighCharts javascript,我正在尝试使用一些在线转换器将其转换为 CoffeeScript。

然而,它们都因“缺少操作数”而出错

这是代码

$(function() {
$('#container').highcharts({
series: [{
name: "<%= x %>'",
data: [
<% @sprice = @price * @quantity %>
<% 0.upto(@years).each do |stack| %>
<%= number_with_precision(@sprice, precision: 2) %>,
<% @sprice = ((@sprice*percentage)/100)+@sprice %>,
<% end %>]
}]
});
});

缺少的操作数在哪里?这与我的 JS 脚本中嵌入的 ruby​​ 有关吗?

脚本在 HTML View 文件中按预期工作。但我正在尝试将其移至 Controller 的 js 文件中以稍微清理它。默认情况下, Controller 的 js 文件位于 coffescript 中,所以这就是我陷入困境的地方。

感谢任何帮助,谢谢!

最佳答案

如上所述:

If @years is small

then ERB a couple simple scalars and then build the array in CoffeeScript;

如果@years很大

then do the heavy lifting in your controller and stuff the data into your CoffeeScript as a one line JSON blob.

或者 AJAX,或者将数据拆分为单独的 JavaScript 片段,并将代码保留为 CoffeeScript。

引用文献

关于javascript - 将 JS 转换为 CoffeScript,缺少操作数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20549546/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com