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