【问题标题】:I don't want to get data as strings in array - coffeescript我不想将数据作为数组中的字符串获取-coffeescript
【发布时间】:2019-04-22 19:48:01
【问题描述】:

这里我正在创建一个数组data

class_enrollment_data_values = (class_id) ->
  data = []
  $.each $("#class_data_#{class_id}").data('enrollment-count'), (index, value) ->
    data.push("{
                x: #{value},
                y: #{index + 1},
                date: #{$("#class_data_#{class_id}").data('enrollment-dates')[index]}
              }")
  data

结果如下:

["{ x: 12, y: 1, date: 11/19/18 }", "{ x: 2, y: 2, date: 11/20/18 }"]

我实际上需要它如下,即没有字符串引号:

[{ x: 12, y: 1, date: 11/19/18 }, { x: 2, y: 2, date: 11/20/18 }]

【问题讨论】:

  • 我猜只是在推送时省略引号
  • 这根本不应该工作,字符串文字内的x: #{value}, 将导致文字子字符串x: #{value},
  • 在推送时省略引号会导致以下错误:SyntaxError: [stdin]:1585:29: unexpected newline

标签: arrays coffeescript


【解决方案1】:

您将其作为字符串推送...删除 - " - 在代码中。

【讨论】:

  • 删除引号后我得到SyntaxError: [stdin]:1585:29: unexpected newline
猜你喜欢
  • 2020-01-04
  • 2012-04-30
  • 2020-05-30
  • 2015-12-21
  • 1970-01-01
  • 2014-02-18
  • 2017-10-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多