JSON Linq.js过滤开始日期结束日期列

时间:2014-11-30 13:04:45

标签: javascript jquery linq.js

我需要使用引用http://linqjs.codeplex.com/在datepicker选择的开始日期和结束日期之间过滤结果,如何根据我的日历输入进行过滤。

开始日期:$('#startdate')。val()// MM / DD / YYYY格式

结束日期:$('#enddate')。val()// MM / DD / YYYY格式

var queryResult = $.Enumerable.From(jsonResultTble) 
.Where("??") 
.ToArray();

示例数据:

var jsonResultTble = [{"ItemId":3,"Condition":"Very Good","Seller":"amazon@hotmail.com","Rating":0,"School":"University of California-Los Angeles","City":" ","State":" ","Comments":"N/A","RetailPrice":0,"ManufactureDate":"4/10/2012 12:00:00 AM","ExpiryDate":"4/10/2014 12:00:00 AM"},{"ItemId":4,"Condition":"Very Good","Seller":"g@esoulconsultancy.com","Rating":18,"School":"Mississippi Valley State University","City":" ","State":" ","Comments":"N/A","RetailPrice":0,"ManufactureDate":"1/10/2010 12:00:00 AM","ExpiryDate":"4/10/2016 12:00:00 AM"]; 

1 个答案:

答案 0 :(得分:1)

您可以执行以下操作,根据日期范围进行过滤:

var startDate = "1/10/2010";
var endDate = "4/10/2010";

var queryResult = Enumerable.From(jsonResultTble)
    .Where(function (x) { return x.ManufactureDate >= startDate && x.ManufactureDate <= endDate })
    .OrderBy(function (x) { return x.Seller })
    .Select(function (x) { return x.Seller })
    .ToArray();

这是LINQ.js的jsFiddle:

http://jsfiddle.net/6mchrmn9/5/

如果你想摆脱json中的时间,而不是x.ManufactureDate,你可以使用类似的东西重新格式化代码:

new Date(x.ManufactureDate).format("dd/m/yyyy");

原型上原生不存在格式化功能,因此请查看:

http://jsfiddle.net/phZr7/508/