开发者

how to filter / query date using dojox.jsonPath.query

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 开发者_Python百科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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜