好的,我使用meteor中的天文包构建了游戏数据库模式。
然后,我尝试通过在服务器中扩展它来添加方法。(server/gamehandle.js)
import {Game} from '../imports/db/game'
import {DDP} from 'meteor/ddp-client'
Game.extend({
meteorMethods: {
AddNewGame(judul){
const invocation = DDP._CurrentInvocation.get()
this.namaGame = judul
this.creator = invocation.userId
this.createdAt = new Date()
return this.save()
}
}
})但是,当我尝试使用callMethod在应用程序客户端中运行该方法时,它抛出了一个错误:天文/执行未找到404。这是使用它的组件
import {Game} from '../../../db/game'
export function NewGameList(props){
const { isOpen, onOpen, onClose } = useDisclosure()
const [judul, setJudul] = useState('')
const [hasil, setHasil] = useState(null)
const judulChange = (e) => setJudul(e.target.value)
const AddGame = new Game()
const handleSubmit = (e) => {
e.preventDefault()
AddGame.callMethod('AddNewGame', judul, (err, result) => {
result ? setHasil(result) : setHasil(err.message)
console.log(err)
})
}
...照亮我,我做错了什么?
发布于 2021-03-17 11:28:48
终于从流星松弛中找到了解决方案。只需要将我的db文件导入到服务器中的主js文件中。
https://stackoverflow.com/questions/66633416
复制相似问题