【发布时间】:2015-07-07 21:38:11
【问题描述】:
我正在用sails.js 编写API,但我在查找对象时遇到了一个问题。
我有带有属性的模型:
attributes: {
firstName:{
type:"string",
required:true,
minLength: 2
},
lastName:{
type:"string",
required:true,
minLength: 2
},
getFullName: function (){
var fl = this.firstName + " " + this.lastName;
return fl;
},
}
现在我想用 getFullName startsWith "xyz qwe" 找到一个对象
我该怎么做?
我试过了:
Patient.find({ getFullName: { 'startsWith': 'Tomas' }}).exec(console.log)
和
Patient.find({ getFullName(): { 'startsWith': 'Tomas' }}).exec(console.log)
两者都不起作用。
我可以在 find() 函数中访问 getFullName 之类的计算属性吗?
这个查询当然有效:
Patient.find({ firstName: { 'startsWith': 'Tomas' }}).exec(console.log)
【问题讨论】:
标签: sails.js