【问题标题】:coffee script - use parameter vairable in json data咖啡脚本 - 在 json 数据中使用参数变量
【发布时间】:2015-01-22 08:25:02
【问题描述】:

我有一个咖啡脚本函数

postData: (pattern) ->
  myData =
    a: "a string"
    pattern: 0
    f: false

它被评估为

{
  "a": "a string",
  "pattern": 0,
  "f": false
}    

这不是我想要的。我希望pattern 成为我传入的字符串

感谢您的帮助。

【问题讨论】:

    标签: json coffeescript


    【解决方案1】:
    postData: (pattern) ->
      myData =
        a: "a string"
        f: false
      myData[pattern] = 0
      return myData
    

    看到它工作here

    【讨论】:

      猜你喜欢
      • 2013-04-01
      • 1970-01-01
      • 2014-10-16
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多