1

我需要使用参考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"]; 
4

1 回答 1

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/

于 2014-11-30T16:33:56.927 回答