Javascript 使用JLinq按日期过滤JSON
我使用它来过滤JSON数据。按日期筛选对我不起作用。我尝试调用方法,但都是一样的 这是我的代码片段Javascript 使用JLinq按日期过滤JSON,javascript,json,Javascript,Json,我使用它来过滤JSON数据。按日期筛选对我不起作用。我尝试调用方法,但都是一样的 这是我的代码片段 //This works jlinq.from(myData) .select(function(rec) { return { title:rec.title, pubDate:rec.pubDa
//This works
jlinq.from(myData)
.select(function(rec) {
return {
title:rec.title,
pubDate:rec.pubDate
}
});
这是上述代码返回的数据
// And returned this data
myData = [
{pubDate: "2012-06-19T10:42:59.000Z",
title: "How caching matters in JS?" },
{pubDate: "2012-06-18T14:39:25.000Z",
title: "Globbing in scripting languages"}
{pubDate: "2012-06-14T17:50:22.000Z",
title: "Inspecting Objects in Scripting"}
]
当我尝试按日期筛选时,它不起作用。大于或小于
已编辑
//Filter by pubDate
jlinq.from(myData)
.greater(new Date("pubDate"), new Date("2010-02-13T19:03:17.000Z"))
.select();
比较日期值时,此问题特定于。它返回空数组
//But Returns empty Array
//[]
我明白了。我认为问题在于库假设值为string comparelength,否则只需比较value1>value2 我更改了此代码:
//is the value greater than the argument
{ name:"greater", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return this.value.length > value; },
string:function() { return this.value.length > value; },
other:function() { return this.value > value; }
});
}},
为此:创建另一个名为greaterDate的筛选器,并将字符串转换为“Date()”
也许有更好的方法,但我用这个解决了它。你的日期是字符串,所以将它们与其他字符串进行比较。。。新日期(2000,3,5).toISOString()我必须在库中执行此操作,因此我添加了日期筛选器。检查我的答案。
//is the value greaterDate than the argument
{ name:"greaterDate", type:framework.command.query,
method:function(value) {
return this.compare({
array:function() { return this.value.length > value; },
string:function() { return new Date(this.value) > new Date(value); },
other:function() { return new Date(this.value) > new Date(value); }
});
}},