2016-08-11 3 views
2

천문학 v2에서 .save() 함수를 사용하면 어떤 이유로 "post.save가 함수가 아닙니다."라는 메시지가 나타납니다. 나는 클라이언트 측에서 유성 메서드 호출을 사용하여 db에 새 문서를 삽입 할 때 .save()를 호출하려고했습니다.Meteor jagi : 천문 .save 함수가 작동하지 않습니다.

는 여기에 몇 가지 코드 : 당신이 newPost라는 추가 방법과 천문학 문서에 샘플을 사용하여 메신저를 볼 수 있듯이

import { Class } from 'meteor/jagi:astronomy'; 
import { Mongo } from 'meteor/mongo'; 

const Posts = new Mongo.Collection("Posts"); 

const Post = Class.create({ 
    name: 'Post', 
    Collection : Posts, 
    secured: true, 
    fields: { 
     title: String, 
     published: Boolean, 
     /* ... */ 
    }, 
    methods: { 
     rename(title) { 
      // Check if a given user can rename this post. 
      if (this.ownerId !== Meteor.userId()) { 
       throw new Meteor.Error(403, 'You are not an owner'); 
      } 
      this.title = this; 
      this.save(); 
     }, 
     publish() { 
      // Check if a given user can publish this post. 
      if (this.ownerId !== Meteor.userId()) { 
       throw new Meteor.Error(403, 'You are not an owner'); 
      } 
      if (this.published) { 
       throw new Meteor.Error(403, 'Post is already published'); 
      } 
      this.published = true; 
      this.save(); 
     } 
    } 
}); 

Meteor.methods({ 
    "newPost"(){ 
     const post = new Post(); 
     post.title = "test"; 
     post.save(); 
    }, 
    "renamePost"(postId, title) { 
     const post = Post.findOne(postId); 
     post.rename(title); 
    }, 
    "publishPost"(postId) { 
     const post = Post.findOne(postId); 
     post.publish(); 
    } 
}); 

.

는 모든 기능에 호출하면

TypeError: post.save is not a function

유무가 성공하지

  • 제거하고 다시 추가 천문학

  • 다시에게와 오류 해결에 다음과 같은 시도를 시도 예외 결과 유성 프로젝트

  • 최신 2.1.2 버전으로 업데이트

답변을위한 Thx!

답변

0

방법처럼 천문학에 대해 몰라. 클래스. 수업을 내보내시겠습니까?

관련 문제