2017-02-11 3 views
1

에서 사전 검증에서 작동하지 않는이 인쇄 -hasOwnProperty 내가 스키마를 몽구스

Before - 
{ title: 'im mr meeseeks', 
    link: null, 
    _id: 589f0f3ddf781803b459dc00, 
    comments: [], 
    upvotes: 2 } 
After - 
{ author: 'Meseeks', 
    title: 'im mr meeseeks', 
    link: null, 
    _id: 589f0f3ddf781803b459dc00, 
    comments: [], 
    upvotes: 2 } 
Creating author 
Pre validate document printing - 
{ author: 'Meseeks', 
    title: 'im mr meeseeks', 
    link: null, 
    _id: 589f0f3ddf781803b459dc00, 
    comments: [], 
    upvotes: 2 } 
Pre validate called. Title : 589f0f3ddf781803b459dc00 
Author is : Meseeks 
hasOwnProperty : false 
this.author=='' : false 
Here 
Post validate called. Title : 589f0f3ddf781803b459dc00 
Pre save called. Title : 589f0f3ddf781803b459dc00 
Post save called. Title : 589f0f3ddf781803b459dc00 

를 내가 저자를 내 라우터에 수동으로 설정하십시오. 그러나 pre init 함수는 객체에 "author"라는 속성이 있는지 확인할 수 없습니다. 이것이 어떻게 가능한지? 내가 뭔가 잘못하고 있니?

해당 속성이 사전 초기화에 있는지 어떻게 확인합니까?

답변

1

코드의이 시점에서 "this"는 Object가 아니라 단지 프로토 타입입니다. 자세한 설명 및 문제 해결 방법은 here입니다.

관련 문제