2017-09-05 139 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

是的,我知道这是架构被定义,而不是我真正想要的。 如果你明白我想实现的目标,你知道一种获得我想要的Schema的方法吗? – piptin