数据模型中某个字段是单选或者多选的定义方式;

 1 /* jshint -W079 */
 2 /* jshint -W020 */
 3 
 4 "use strict";
 5 var _ = require("lodash");
 6 
 7 module.exports = function(utils, db) {
 8     // Model LotteryReceiveRecord 领奖记录
 9     global.LotteryReceiveRecordSchema = new db.Schema({
10         user: {type: db.ObjectId, ref: 'User'},
11         lottery: {type: db.ObjectId, ref: 'Lottery'},
12         prize: {type: db.ObjectId, ref: 'Prize'},
13         username:String,
14         phone:String,
15         address:String,
16         time: Date,
17         end: Date,
18         zipcode:String,
19         //此处type字段就是多选或者单选字段,此字段存成数字类型;
20         type:{type:Number,default:0},
21         idcard: {
22             a: String,
23             b: String
24         }
25     }, db.schema_options);
26 
27     global.LotteryReceiveRecord = db.mongoose.model('LotteryReceiveRecord', LotteryReceiveRecordSchema);
28     //此处全局变量,对应上面的type字段;
29     global.LotteryReceiveTypes = {
30         receive: { t: '已领取', v: 0},
31         unregistered: { t: '未登记', v: 1},
32         failure: { t: '发送失败', v: 2},
33         overdue: { t: '已过期', v: 3}
34     };
35 };
 1 <!doctype html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6 </head>
 7 <body>
 8 <select id="type_filter" class="form-control" value="{{item.type}}" title="类型" name="type">
 9     <!-- type是传递的前面的LotteryReceiveRecord-->
10     <!-- item传递的是LotteryReceiveRecordSchema的数据-->
11     <!-- 原理就是,当item的某个字段与type的某个属性相同或不同时,该如何显示-->
12     {% for t in types %}
13     <option value="{{loop.index - 1}}" {% if item.type == t.v %}selected{% endif %}>{{t.t}}</option>
14     {% endfor %}
15 </select>
16 </body>
17 </html>
坚持下去就能成功
原文地址:https://www.cnblogs.com/suoking/p/4988883.html