【发布时间】:2014-08-20 22:55:06
【问题描述】:
我想为我的流星应用创建一个管理表单;在从头开始构建一个之前,我打算尝试 Ogno Admin,但我不确定它是否可以支持我需要的格式的数据。我当前的应用数据像这样进入 mongo:
Beaches.insert({
"name": "Entry name",
/* location stored like this so I can use mongo $near queries */
"location": {
"type": "Point",
"coordinates": [-5.0990296,50.110757]
},
/* could be many images, minimum 1 */
"images": [
{
"url": "image1.jpg",
"caption": "Image caption"
}
],
"shortDesc": "A delightful description...",
/* fixed list of attributes stored as objects */
"attributes": {
"attr 1": {
"score": 2,
"text": "attr1 text"
},
我可以编写一个简单的模式来支持上面的不同数组/对象(尤其是位置坐标)吗?它们必须是方括号格式的 [lng, lat] - ogno admin 可以使用它,还是我必须编写自定义管理内容?对我来说,用其他方式构建管理站点并让它为 Meteor 输出 JSON 数据可能会更容易。
使用可能的架构代码更新
Beaches = new SimpleSchema({
name: {
type: String,
},
location: {
type: [Object]
},
location.$.type: {
/* how do I force '"type" : "Point" into every entry?
use 'autovalue' with the .clean() function?*/
},
location.$.coordinates: {
/* how do I ensure a [x,y] array in here? */
},
images: {
type: [Object]
},
"images.$.url": {
type: String
},
"images.$.caption": {
type: String
},
attributes: {
type: [Object]
},
/* note that my attributes above are all prefixed with a 'name'
eg. "attr 1" : {}
I'm not sure how to declare these either!
*/
...
});
【问题讨论】:
-
是的,简单模式适用于位置坐标。你有什么努力吗?我不知道 Ogno 管理员,但在文档中写道,他们使用简单模式进行验证,因此它应该使用简单模式。
-
我只是不确定如何格式化位置——尤其是坐标数组——我不想在数据前加上“lng”和“lat”,而简单模式没有;没有一个“数组”类型(仅限字符串、数字、布尔值和对象)
-
简单模式确实有一个数组类型。
[object]到这里 (github.com/aldeed/meteor-simple-schema) 并搜索“指示存在数组”