在这个SailsJS模型中,我们在' In '键属性中保留了静态选项值。
status: {
type : 'string',
defaultsTo : 'Active',
in : ['Active', 'InActive']
}
这些值在REST API中可用->最好是/OPTIONS格式?
愿意为这些常量值提供一个真理来源。想了解如何通过REST API为前端应用程序发送这些值的最佳实践。当前端应用程序和第三方API用户都可以获得相同的真实来源时,那么维护应用程序就很容易了。请建议。
thank and Regards, Raj
恐怕你必须制作一个OptionController并手动完成它。对于这些静态选项,您可以将它们写入配置文件中,然后使用sails.config.xxx访问它们。例如:在config/whatever.js
module.exports={
activeChoices:['active','inactive','donotknow','xxx']
}
创建OptionController.js,并设置路由
Route.js
'GET /statusOptions/ :{
controller:'OptionController',
action:'statusOptions'
}
在你的api/Controller/OptionController.js中
module.exports={
statusOptions:function(req,res){
return res.json(sails.config.activeChoices);
}
}
在你的模型
status:{type:'string',defaultsTo:'Active',in:sails.config.activeChoices}