如何使用 dojox.jsonPath.query 过滤/查询日期
我指的是使用 http://www.sitepen.com/ blog/2008/03/17/jsonpath-support/
这就是我正在做的事情(花了两天但没有运气): 首先绘制一个包含整数列和日期列的数据网格,还可以通过单击列标题对列值进行排序。
来查询数字
jsonStore = new dojox.jsonPath.query(object,"[?(@.+ field1 > 500)]");//works fine
现在使用 dojox.jsonPath.query 使用类似语法(使用 jsonStore 重绘网格) 。到目前为止一切正常。
但现在尝试使用 jsonPath 过滤出 dojo 数据网格另一列上的日期。
var dt = new Date();
jsonStore = new dojox.jsonPath.query(object,"[?(@.effectiveDate<" + dt + ")]");// does not work
// I am trying to get the rows of the grid which have effectiveDate date less
// than cuurent date or any other passed 'javascript date object'
layout = [{"field":"field1","name":"field1"},{"type":dojox.grid.cells.DateTextBox,"field":"effectiveDate","name":"effectiveDate","formatter":formatDate}];
其中 effectiveDate 是 dojo 数据网格布局的字段。但上面的方法不起作用并抛出以下错误 “jsonPath:缺少;在声明之前:_v. effectiveDate
我该如何使用 jsonPath 来查询日期,或者我的语法是错误的?
有没有办法我们可以使用 dojox.jsonPath.query 或 dojox.json.query 使用 <、<=、>=、= 运算符来查询 json 对象中的日期对象....?
有什么帮助吗?
I am referring to use http://www.sitepen.com/blog/2008/03/17/jsonpath-support/
This is what I am doing (spent two days but no luck):
first drawing a datagrid with integer column and a date column and also able to sort the columns values by clicking on the column header..
now using dojox.jsonPath.query to query numbers using syntax like
jsonStore = new dojox.jsonPath.query(object,"[?(@.+ field1 > 500)]");//works fine
(using jsonStore to redraw the grid).. everything works fine till now.
But now trying to filter out dates on the other column for dojo datagrid using jsonPath.
var dt = new Date();
jsonStore = new dojox.jsonPath.query(object,"[?(@.effectiveDate<" + dt + ")]");// does not work
// I am trying to get the rows of the grid which have effectiveDate date less
// than cuurent date or any other passed 'javascript date object'
layout = [{"field":"field1","name":"field1"},{"type":dojox.grid.cells.DateTextBox,"field":"effectiveDate","name":"effectiveDate","formatter":formatDate}];
where effectiveDate is the field for the layout of dojo datagrid. but the above does not work and throws following error
"jsonPath: missing ; before statement: _v.effectiveDate
How shall i use jsonPath to query date, or my syntax is just wrong?
Is there a way we could use dojox.jsonPath.query or dojox.json.query to query date objects in the json object using <, <=, >=, = operators....??
Any help ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 中的日期有问题。由于 JSON 中没有原生的日期类型支持,因此必须使用数字或字符串表示形式来表示日期。您如何在要比较的 JSON 中表示 Date 对象?如果您在数据和查询中使用一致的表示,并且选择可比较的方法,那么这应该可行。出于多种原因,“ISO”时间戳是最好的(请参阅 dojo.date.stamp),并且最常在 JSON 中使用。应避免使用 Date.toString(通过与上面的“+”连接隐式使用的内容),它不可排序,甚至在浏览器之间也不一致。
Dates are problematic in JSON. Because there is no native Date type support in JSON, Dates must be represented using a number or string representation. How are you representing the Date objects in the JSON you're comparing against? If you use a consistent representation in your data and your query, and you choose a method which is comparable, this should work. "ISO" timestamps are best for a number of reasons (see dojo.date.stamp) and are most often used in JSON. Date.toString (what you're implicitly using by concatenating with "+" above) should be avoided, not being sortable and not even being consistent across browsers.