2017-07-27 184 views
0

如何通過調用Meteor js中的集合來填充簡單模式的默認值,而不是如下所示在defaultValue中定義「tests」?如果可能使defaultValue從TestList = new Mongo.Collection('testList')返回全部。Simple Schema從集合中填充默認值

StudentSchema = new SimpleSchema({ 

tests: { 
type: [Object], 
blackbox: true, 
optional: true, 

defaultValue:[ 
    { 
     "_id" : "T2yfqWJ3a5rQz64WN", 
     "category_id" : "5", 
     "active" : "true", 
     "category" : "Cognitive/Intelligence", 
     "abbr" : "WJ-IV COG", 
     "name" : "Woodcock-Johnson IV, Tests of Cognitive Abilities", 
     "publisher" : "Riverside Publishing" 
    }, 


    { 
     "_id" : "Ai8bT6dLYGQRDfvKe", 
     "category_id" : "5", 
     "active" : "true", 
     "category" : "Cognitive/Intelligence", 
     "abbr" : "WISC-IV", 
     "name" : "Wechsler Intelligence Scale for Children-Fourth Edition", 
     "publisher" : "The Psychological Corporation" 
    }, 

    { 
     "_id" : "osAuaLrX97meRZuda", 
     "category_id" : "7", 
     "active" : "true", 
     "category" : "Speech and Language", 
     "abbr" : "WOJO", 
     "name" : "Wechsler Intelligence", 
     "publisher" : "The Psychological Corporation" 
    }, 

    { 
     "_id" : "57c62a784b94c533b656dba8", 
     "category_id" : "5", 
     "active" : "true", 
     "category" : "Behavioral", 
     "abbr" : "CARS", 
     "name" : "CARS", 
     "publisher" : "The Psychological Corporation" 
    } 
], 

); },

回答

0

將「TestList」集合中的所有條目動態加載到「tests」數組中。

TestList = new Mongo.Collection('testList'); 
StudentSchema = new SimpleSchema({ 

tests: { 
type: [Object], 
blackbox: true, 
optional: true, 
autoValue: function() { 
return TestList.find().fetch(); 
},