1

내가 SimpleSchema에 필드 아래에 사용하고 주어진 설정하지 않습니다. 문제는 빈 문자열 으로 필드를 업데이트 할 때 (즉, 텍스트 상자를 비워 두는 것) 일 때, 값 -은 위의 SimpleSchema 코드에서 필드 정의대로 설정되지 않습니다.autoValue는 값

나는 아래로

clients.js:79 this {isSet: true, value: "", operator: "$unset", unset: ƒ, field: ƒ, …} 
clients.js:80 typeof this.value.length number 
clients.js:81 this.value.length 0 true true 
clients.js:82 this.value string 
clients.js:83 this.operator $unset 
clients.js:84 this.isSet true 
clients.js:86 if part ran. 
clients.js:79 this {isSet: true, value: "-", operator: "$unset", unset: ƒ, field: ƒ, …} 
clients.js:80 typeof this.value.length number 
clients.js:81 this.value.length 1 false false 
clients.js:82 this.value - string 
clients.js:83 this.operator $unset 
clients.js:84 this.isSet true 
clients.js:89 else part ran.  

를 로그를 얻고 내 컬렉션의 문서는 필드 fileNo이 없습니다.

무엇이 누락 되었습니까? 원하는 값은 fileNo의 값이 일 때 - (하이픈)으로 설정해야합니다. 문서에서는 당신은이 상황을 처리해야 fileNo : "-"

+0

정확히 무엇을 너 성취하려고? – Styx

+0

@Styx : 마지막 줄을 굵게 수정했습니다. 미리 감사드립니다. –

+0

아마, 'defaultValue'가 당신이 필요로하는 것일까요? – Styx

답변

0

과 같이해야합니다 빈 (정의) value

  1. 문서 insertfileNo을 위해.

  2. 에 대해 value 공백이있는 update 문서. 그 값이 빈 문자열 (optional: true) 인 경우

    두 번째 경우

, 유효성 검사기는 문서에서 필드를 제거하려고합니다. 우리는 이것을 잡아서 막을 수 있습니다.

fileNo: { 
    type: String, 
    label: 'File No.', 
    autoValue() { 
     if (this.isInsert && (this.value == null || !this.value.length)) { 
     return '-'; 
     } 
     if (this.isUpdate && this.isSet && this.operator === '$unset') { 
     return { $set: '-' }; 
     } 
    }, 
    optional: true 
    } 

추가 :이 답변을 작성하는 데 사용 설명서 (예상대로 코드가 작동합니다 로컬 테스트) :

+0

다시 한번 감사드립니다. 당신은 내 시간을 많이 절약했습니다. 이것은 매우 좁은 케이스였습니다. 해결할 수 없었습니다. –

+0

@AnkurSoni 환영합니다 :) 문서를 완전히 읽는 것이 도움이됩니다.) – Styx

+0

또한 문서의 링크와 라인 번호를 가리킬 수 있습니까? 당신 대답에? –