How to use enum values in dropdown?

382 views
Skip to first unread message

kabrod

unread,
Mar 22, 2011, 4:10:16 PM3/22/11
to Mongoose Node.JS ORM
I'm using Express and Jade, but can't find an example on how to access
and iterate enum values.

Thanks, kabrod

Siegfried Ehret

unread,
Mar 22, 2011, 6:00:42 PM3/22/11
to mongoo...@googlegroups.com
each and forEach doesn't do what you want ?

kabrod

unread,
Mar 26, 2011, 3:23:56 AM3/26/11
to Mongoose Node.JS ORM
My first question wasn't clear, sorry.
The problem is how to access the enum values, not to iterate them.

The enums are declared in the Mongoose model.
So, do I access the enum collection from the database or the model
object?

Either way, what is the syntax for doing this?


Thanks, kabrod

Dasher

unread,
Apr 18, 2011, 6:44:42 PM4/18/11
to Mongoose Node.JS ORM

Drop the following into a plugin or in your schema:

schema.method({
fieldProperties:
function (fieldName, propertyName) {
fieldRef = schema.path(fieldName);
if (fieldRef.options[propertyName]) {
return fieldRef.options[propertyName];
}

return;
},
});

Then you can use it with:
someRecord.fieldProperties('fieldName', 'enum'));

You can use it for most options of a field - just keep in mind that
you may need to use the result as a function if the property is a
function - ie a calculated default.
It'll return undefined if the property doesn't exist.

Dasher
Reply all
Reply to author
Forward
0 new messages