Strongloop 相关模型 returns 函数,不是对象
Strongloop related model returns function, not object
我尝试向 mongoDB 提出请求:
GeoData.find({
include: {relation: 'Account'} ,
where: {
and: [{
Coordinate: {
near: alarm.Geopoint,
maxDistance: maxDist.Value,
unit: 'meters'
}
}, {Time: {gt: fromTime}}]
}
},function(err, datas){
_.each(geoDatas, function(val){
console.log(val); //line 1
console.log(val.Account); //line 2
})}
然后执行查询,我收到意想不到的结果:
在第 1 行 - 我可以将 Account 对象视为 val 对象的 属性
在第 2 行 - 我可以看到那个对象:
{ [Function: bound ]
getAsync: [Function: bound ],
update: [Function: bound ],
destroy: [Function: bound ],
create: [Function: bound ],
build: [Function: bound ],
_targetClass: 'Account' }
为什么我查看函数而不是对象?
我如何访问对象?
通过
解决
let str = JSON.stringify(gData);
eval('gData = '+str);
我尝试向 mongoDB 提出请求:
GeoData.find({ include: {relation: 'Account'} , where: { and: [{ Coordinate: { near: alarm.Geopoint, maxDistance: maxDist.Value, unit: 'meters' } }, {Time: {gt: fromTime}}] } },function(err, datas){ _.each(geoDatas, function(val){ console.log(val); //line 1 console.log(val.Account); //line 2 })}
然后执行查询,我收到意想不到的结果: 在第 1 行 - 我可以将 Account 对象视为 val 对象的 属性 在第 2 行 - 我可以看到那个对象:
{ [Function: bound ] getAsync: [Function: bound ], update: [Function: bound ], destroy: [Function: bound ], create: [Function: bound ], build: [Function: bound ], _targetClass: 'Account' }
为什么我查看函数而不是对象?
我如何访问对象?
通过
解决
let str = JSON.stringify(gData);
eval('gData = '+str);