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

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值