我想知道是否有一个函数来检查我的模型在服务器端是否有效,我在express上使用locomotivejs.
这是我的模型架构
var BillSchema = new Schema({
BrandId:Schema.Types.ObjectId,
ModelNo:{ type: String, required: true },
BillNo:{ type: String, required: true },
years:Number,
months:Number,
})
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我从视图中接收值.
var bill=new Bill();
bill.CategoryId=self.param('CategoryId');
bill.BrandId=self.param("BrandId");
bill.ModelNo=self.param("Model");
bill.BillNo=self.param("BillNo");
if(bill.categoryId!="" && bill.BrandId!="" && bill.ModelNo!="" && bill.years!="")
{
// code to save the values to db
}
Run Code Online (Sandbox Code Playgroud)
有没有办法避免这种验证
if(bill.categoryId!="" && bill.BrandId!="" && bill.ModelNo!="" && bill.years!="")
Run Code Online (Sandbox Code Playgroud)
与ModelState.Isvalid.Net MVC中的内容类似
提前致谢...