简体   繁体   中英

Is it possible to list the allowedValues of a SimpleSchema schema in the client using meteor?

I am using Simple Schema to validate my database entries in a meteor application. I started developing a module to create forms automatically (I know autoform is quite good, but it was not exactly what I needed). To make the radio component I need to know the allowed values for that field, and since it was already specified in the schema I wanted to know if it is possible to retrieve it. Any ideas?

Consider a very simple schema:

s=new SimpleSchema({
  list: {
    type: String,
    allowedValues: ["foo","bar"]
  }
});

If you explore the created object you'll find that:

s._schema['list'].allowedValues

returns

["foo", "bar"]

One can deduce the general pattern is:

schemaObject._schema['keyName'].allowedValues

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM