gpt4 book ai didi

javascript - 使用 coffeescript 时定义 Meteor 集合; ReferenceError 说集合未定义

转载 作者:行者123 更新时间:2023-11-29 17:16:10 27 4
gpt4 key购买 nike

我正在使用 CoffeeScript 。我在网上读到,当将 coffeescript 与 Meteor 一起使用时,全局变量,如集合,应该使用@来定义。我已经这样做了,但我仍然收到以下错误。相关文件中的代码出现在错误之后。我该如何解决这个错误?

谢谢。

错误--------

ReferenceError: GameStatus is not defined
at app/server/methods/adminMethods.coffee.js:10:5

--------------------------------收藏/gamestatus.coffee----------------------------------

@GameStatus = new Meteor.Collection('gamestatus')

--------------------------------服务器/adminMethods.coffee----------------------------------

Meteor.methods
initializeGameStatus: () ->
GameStatus.insert({gameOnOff: 0, asymmetric: 0})


if GameStatus.find({}).count() is 0
Meteor.call 'initializeGameStatus', (err, result) ->
if err
console.log(err)
else
'GameStatus collection initialized'

最佳答案

除了全局范围之外,它还可以是文件加载顺序。为确保您的集合已加载,首先将您的 collections 目录移动到 /lib 目录

关于javascript - 使用 coffeescript 时定义 Meteor 集合; ReferenceError 说集合未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17603223/

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