2017-09-05 17 views
0

node-simple-schema에있는 GeoJSON 스키마를 내 응용 프로그램에서 정의하려고합니다.배열 스키마를 SimpleSchema로 다시 사용하는 방법

나중에 Point, LineString, .. 지오메트리를 정의 할 때 위치, 선 스트링, 라이너 및 다각형 배열을 정의하여 사용하려고합니다.

이것은 내가 지금하고있는 일이며 작동하지 않습니다.

const Position = new SimpleSchema({ 
    position: { 
    type: Array, 
    label: 'A single position. ...', 
    minCount: 2, 
    maxCount: 3, 
    }, 
    'position.$': { 
    type: Number, 
    label: 'A number representing...', 
    }, 
}); 

const Point = new SimpleSchema({ 
    type: { 
    type: String, 
    label: 'The type of the feature.', 
    allowedValues: ['Point'], 
    }, 
    coordinates: { 
    type: Position.pick('position'), 
    // this does not work either 
    // type: Position.getObjectSchema('position'), 
    label: 'A single position', 
    }, 
}); 

이와 같이 유효성을 검사하려고하면 오류가 발생합니다.

const PointExample = { 
    type: 'Point', 
    coordinates: [180.0, 46.5, 100], 
}; 

Point.validate(PointExample); 

답변

0

추출 된 스키마는 키와 값이 모두있는 개체를 찾습니다. 따라서 다음은 핵심 '위치'검증을 제공했습니다.

const PointExample = { 
    type: 'Point', 
    coordinates: { 
    position: [180.0, 46.5, 100] // This is what matches the 'Position' schema. 
    } 
}; 

Point.validate(PointExample); 
+0

예, 저는 실제로 원하는 스키마가 아니라 정의 된 스키마라는 것을 알고 있습니다. 내가 원하는 것을 이해한다면, 내가 원하는 스키마를 얻는 방법을 알고 있습니까? – piptin