JSON Linq.js 筛选开始日期结束日期列

JSON Linq.js filter on start date end date column

本文关键字:日期 结束 开始 筛选 Linq js JSON      更新时间:2023-09-26

我需要使用参考 http://linqjs.codeplex.com/如何根据日历输入过滤日期选择器选择的开始日期和结束日期之间的结果。

开始日期 : $('#startdate').val()//月/日/年格式

结束日期 : $('#enddate').val()//月/日/年格式

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"]; 

您可以执行以下操作来根据日期范围进行筛选:

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/