【问题标题】:JSON Linq.js filter on start date end date column开始日期结束日期列上的 JSON Linq.js 过滤器
【发布时间】:2015-01-28 13:57:57
【问题描述】:

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

开始日期:$('#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"]; 

【问题讨论】:

  • 你能提供一个 jsonResultTble 的例子吗?
  • 感谢 ZenCoder。我添加了一个示例。请注意它也有时间。虽然它可以忽略。
  • 你得到了答案。如果你还需要什么,请告诉我。
  • @coder 看看这个:neue.cc/reference.htm

标签: javascript jquery linq.js


【解决方案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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    • 1970-01-01
    • 2023-03-17
    • 2017-01-15
    • 1970-01-01
    • 2018-08-19
    • 2012-08-19
    相关资源
    最近更新 更多