我试图营造一种特定的简单模式的一个集合,我想,以确保:Aldeed Simple-Schema,如何在另一个字段中使用允许的值?
当用户在我selectsCollection进入一个新的选择,他会把期权价值为一体选定的值。
例如:
SelectsCollection.insert({name:"SelectOne",deviceType:"Select",options:["option1","option2","option3"],value:"option4",description:"This is the first select"});
这没有工作。我希望他只写3个选项中的一个。
这里我的架构:
SelectsCollection = new Mongo.Collection('Selects'); //Create a table
SelectsSchema = new SimpleSchema({
name:{
type: String,
label:"Name",
unique:true
},
deviceType:{
type: String,
allowedValues: ['Select'],
label:"Type of Device"
},
options:{
type: [String],
minCount:2,
maxcount:5,
label:"Select Values"
},
value:{
type: String,
//allowedValues:[options] a kind of syntax
// or allowedValues:function(){ // some instructions to retrieve the array of string of the option field ?}
label:"Selected Value"
},
description:{
type: String,
label:"Description"
},
createdAt:{
type: Date,
label:"Created At",
autoValue: function(){
return new Date()
}
}
});
SelectsCollection.attachSchema(SelectsSchema);
任何想法? :)
非常感谢!
我不认为这是可以只能用简单模式来完成。请详细说明为什么你不能简单地检查纯JS如果'价值'是在'选项'数组? if(options.indexOf(value)!== -1){// insert}'。 –
我用'if(options.indexOf(value)!== -1){//插入}'作为Khang的一个自定义验证,你建议:) –