Here my data:
这里我的数据:
[
{
"idi": 0,
"ut": 1479679625,
"eid": 0,
"ide": 0
},
{
"idi": 1,
"ut": 1479679630,
"eid": 1,
"ide": 0
},
{
"idi": 2,
"ut": 1479679650,
"eid": 0,
"ide": 1
},
{
"idi": 3,
"ut": 1479679655,
"eid": 1,
"ide": 1
}
]
ut
is unix timestamp, I need to get all objects between range of 2 ut values. like >= 1479679625 && <= 1479679655 (all objects between first & last object). I use lodash with lowdb and nodejs:
ut是unix时间戳,我需要在两个ut值之间获取所有对象。比如>= 1479679625 && <= 1479679655 (first & last object之间的所有对象)。我用lodash搭配lowdb和nodejs:
const low = require('lowdb');
var _ = require('lodash');
var DB = low('pathDB');
var TIME_QUERY_START_UNIX = 1479679625;
var TIME_QUERY_STOP_UNIX = 1479679655;
var QUERY = _.filter(DB, function(o) { return TIME_QUERY_START_UNIX <= o.ut && o.ut <= TIME_QUERY_STOP_UNIX; });
but it throws an
但它抛出一个
Cannot read property 'ut' of undefined
不能读取未定义的属性“ut”。
How I do a right command?
我如何做正确的命令?
Thanks
谢谢
1 个解决方案
#1
2
_.filter(data, function(item) {
return _.inRange(
item.ut,
TIME_QUERY_START_UNIX,
TIME_QUERY_STOP_UNIX + 1
);
})
check item.eid = 0
检查项目。开斋节= 0
_.filter(data, function(item) {
return _.every([
_.inRange(
item.ut,
TIME_QUERY_START_UNIX,
TIME_QUERY_STOP_UNIX + 1
),
item.eid === 0
]);
})
#1
2
_.filter(data, function(item) {
return _.inRange(
item.ut,
TIME_QUERY_START_UNIX,
TIME_QUERY_STOP_UNIX + 1
);
})
check item.eid = 0
检查项目。开斋节= 0
_.filter(data, function(item) {
return _.every([
_.inRange(
item.ut,
TIME_QUERY_START_UNIX,
TIME_QUERY_STOP_UNIX + 1
),
item.eid === 0
]);
})