我正在使用collection2,我试图让它来处理验证是一种特定的方式.我有一个看起来像这样的配置文件架构:
Schema.UserProfile = new SimpleSchema({
name: {
type: String,
optional: false
}
location: {
type: String,
optional: true
}
gender: {
type: String,
optional: false
}
});
Schema.User = new SimpleSchema({
username: {
type: String,
optional: true
},
emails: {
type: Array,
optional: true
},
"emails.$": {
type: Object
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: {
type: Schema.UserProfile,
optional: true
},
services: {
type: Object, …Run Code Online (Sandbox Code Playgroud) 我有以下SimpleSchema,我试图添加自定义验证以验证输入重复的客户名称,但每当我尝试保存新客户时,我收到错误:
提供调用'adminCheckNewCustomerName'结果的异常:TypeError:无法读取null的'namedContext'属性
有人可以请告诉我我在做错了什么/在这里缺少来验证客户名称是否有重复记录?谢谢
schema.js:
AdminSection.schemas.customer = new SimpleSchema({
CustomerName: {
type: String,
label: "Customer Name",
unique: true,
custom: function() {
if (Meteor.isClient && this.isSet) {
Meteor.call("adminCheckNewCustomerName", this.value, function(error, result) {
if (result) {
Customer.simpleSchema().namedContext("newCustomerForm").addInvalidKeys([{
name: "CustomerName",
type: "notUnique"
}]);
}
});
}
}
}
});
UI.registerHelper('AdminSchemas', function() {
return AdminSection.schemas;
});
Run Code Online (Sandbox Code Playgroud)
form.html:
{{#autoForm id="newCustomerForm" schema=AdminSchemas.customer validation="submit" type="method" meteormethod="adminNewCustomer"}}
{{>afQuickField name="CustomerName"}}
<button type="submit" class="btn btn-primary">Save Customer</button>
{{/autoForm}}
Run Code Online (Sandbox Code Playgroud)
collections.js:
this.Customer = new Mongo.Collection("customers");
Run Code Online (Sandbox Code Playgroud) javascript meteor meteor-autoform meteor-collection2 simple-schema
我需要一些建议,以便在我的meteor-app中构建正确的角色架构和管理.
结构体
alanning:roles@1.2.13添加角色管理功能的应用程序.模块中的类别
模块的结构如下:
elementSchema = new SimpleSchema({
element: {type: String, optional: true}
});
Cars.attachSchema(new SimpleSchema({
title: { type: String },
content: { type: String },
category: { type: [elementSchema], optional: true },
});
Run Code Online (Sandbox Code Playgroud)
如您所见,所有可用类别都在模块的Collection中.
权
这就是我在技术上进行身份验证的方式:
router.js
var filters = {
authenticate: function () {
var user;
if (Meteor.loggingIn()) {
this.layout('login');
this.render('loading');
} else {
user = Meteor.user();
if (!user) {
this.layout('login');
this.render('signin');
return;
}
this.layout('Standard');
this.next();
} …Run Code Online (Sandbox Code Playgroud) 在我的Stacks架构中,我有一个dimensions定义如下的属性:
dimensions: {
type: [String],
autoform: {
options: function() {
return Dimensions.find().map(function(d) {
return { label: d.name, value: d._id };
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
这非常有效,并且使用Mongol我能够看到通过表单插入数据的尝试运行良好(在这种情况下,我选择了两个要插入的维度)
然而,我真正的是存储实际维度对象而不是密钥的数据.像这样的东西:
[![蒙古好[2]](https://i.stack.imgur.com/cYBCg.png)
要努力实现这一点,我改变了type:[String]对type:[DimensionSchema]和value: d._id对value: d.这里的想法是我告诉表格我期待一个对象,现在我正在返回对象本身.
但是当我运行它时,我在控制台中收到以下错误.
Meteor当前不支持ObjectID以外的对象作为ID
稍微调整一下并type:[DimensionSchema]改为type: DimensionSchema我在控制台中看到一些新错误(可能是当它type是一个阵列时它们会被埋没
所以似乎autoform试图获取我想要存储在数据库中的值并尝试将其用作id.有关最佳方法的任何想法吗?
这里参考是我的 DimensionSchema
export const DimensionSchema = new SimpleSchema({
name: {
type: String,
label: "Name"
},
value: {
type: Number,
decimal: true,
label: "Value",
min: 0
},
tol: …Run Code Online (Sandbox Code Playgroud) mongodb meteor meteor-autoform meteor-collection2 simple-schema
我是Meteor AutoForm的新手。我想使用国家/地区文档更新播放器文档。下面是我的代码。如果我{{> afQuickField name="country"}}在AutoForm中添加它不起作用。{{> afQuickField name="name"}}单独工作正常。如何(_id,slug,name)在玩家国家/地区字段中添加整个国家/地区的文档?
JS:
CountrySchema = new SimpleSchema({
_id: {
type: String,
index: true
},
slug: {
type: String,
max: 100,
index: true
},
name: {
type: String,
max: 100
}
});
Player.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Player name",
index: true
},
country: {
type: [CountrySchema],
label: "country",
max: 5,
index: true,
autoform: {
options: function() {
return Country.find().fetch().map(function(object) {
return {
label: object.name,
value: object._id
};
});
} …Run Code Online (Sandbox Code Playgroud) 如何以"插入"形式传递字段的默认值?
我正在使用Meteor的软件包:Autoform,Collections2和Simple-Schema.
我的过程是:
无法弄清楚如何使用URL(或任何其他方式)传递参数.问题是如何使用值初始化表单.
假设我有一个URL:
http://localhost:3000/activity/new/Sport
Run Code Online (Sandbox Code Playgroud)
=============== router.js:
...
Router.map(function () {
...
this.route('newActivity', {
path: '/activity/new/:tag',
data: function() {
Session.set('tag', this.params.tag);
return null;
}
});
...
Run Code Online (Sandbox Code Playgroud)
=============== models/activity.js
...
Activities = new Meteor.Collection("activities", {
schema: {
title: {
type: String,
label: '????????'
},
...
tag: {
type: String,
label: '???'
}
}
});
Run Code Online (Sandbox Code Playgroud)
================ templates/avtibity.js
...
Template.newActivity.helpers({
defaultTag: function() {
return Session.get('tag');
}
});
...
Run Code Online (Sandbox Code Playgroud)
================ templates/activity.html
...
<template name="newActivity">
<h1>Create new Activity!</h1>
{{#autoForm collection="Activities" id="insertActivityForm" type="insert"}} …Run Code Online (Sandbox Code Playgroud) 我使用Simple Schema设置了我的集合:
SubLinkSchema = new SimpleSchema({
name: {
type: String,
label: 'Link Name',
unique: false
},
link: {
type: String,
regEx: SimpleSchema.RegEx.Url,
label: 'Custom Link',
optional: true,
autoform: {
class: 'sub-custom-link'
}
}
});
LinkSchema = new SimpleSchema({
name: {
type: String,
label: 'Link Name',
unique: false
},
link: {
type: String,
regEx: SimpleSchema.RegEx.Url,
label: 'Custom Link',
optional: true,
autoform: {
class: 'main-custom-link'
}
},
subLinks: {
optional: true,
label: 'Sub Links',
unique: false,
type: [SubLinkSchema]
}
});
Run Code Online (Sandbox Code Playgroud)
在这里,问题是,子链接没有获得ID.很难在没有id的情况下更新它们.那么,我如何为每个子链接(嵌入文档)生成唯一ID?
为了确保我的出版物接收的参数类型,我应该使用SimpleSchema还是check()?
Meteor.publish('todos.inList', function(listId, limit) {
new SimpleSchema({
listId: { type: String },
limit: { type: Number }
}).validate({ listId, limit });
[...]
});
Run Code Online (Sandbox Code Playgroud)
要么
Meteor.publish('todos.inList', function(listId, limit) {
check(listId, String);
check (limit, Number);
[...]
});
Run Code Online (Sandbox Code Playgroud) 我正在使用简单架构,我想有一种方法可以根据预定义列表或其他字段来验证某些字段中的值
针对未更改的预定义列表(例如枚举)进行验证。可以使用复杂的正则表达式来完成此操作,但这感觉不对:
dialogType: {
type: String,
label: "Dialog Type", // 'article', 'sentence','exercise','lesson','word'
optional: false
},
Run Code Online (Sandbox Code Playgroud)
针对用户集合进行验证,可能会应用某些过滤器:
userId: {
type: String,
label: "User ID",
optional: false
}
Run Code Online (Sandbox Code Playgroud)
一个相关问题 以简单模式将allowedValues绑定到集合中的值
我正在学习流星的绳索,有点迷失在这里.我正在使用collections2,autoform来构建我的应用程序.我想将该集合与用户ID信息一起存储.因此,当我们从服务器检索集合时,我想只显示用户创建的集合而不是其他所有集合.这是架构.
ExercisesSchema = new SimpleSchema({
"name": {
type: String,
label: 'Name'
},
"workout.$.weight": {
type: String,
label: 'Weight'
},
"workout.$.reps": {
type: String,
label: 'Reps'
},
"notes": {
type: String,
label: 'Notes',
optional: true
}
});
Run Code Online (Sandbox Code Playgroud)
在服务器端,我只想显示用户创建的锻炼
Meteor.publish('exercises', function () {
return Exercises.find({owner: this.userId});
});
Run Code Online (Sandbox Code Playgroud)
当我将用户id添加到模式中时,它显示在autoform中,我不知道如何隐藏它,如果我隐藏它,那么我可以在autoform中使用钩子来添加值吗?
这是我的问题:
我想使用simple-schema的强大功能来检查我对以下模式的插入:
let UprocSchema = new SimpleSchema({
"name": { type : String, label: "Nom Uproc" },
"label": { type : String, label: "Libellé Uproc" },
"status": { type : String, label: "Status UPR" }
});
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我忽略了,即使SimpleSchema似乎很好地实现了,我也不能在Mongo.Collection上使用attachSchema属性.
这是我的代码:
let repo_collection = new Mongo.Collection('repository');
export const Repository = new MongoObservable.Collection<Uproc>('repo_collection');
repo_collection.attachSchema( UprocSchema );
Run Code Online (Sandbox Code Playgroud)
这是我的错误消息:
"Collection <{}>"类型中不存在属性"attachSchema".
TypeError:repo_collection.attachSchema不是函数