gpt4 book ai didi

javascript - 在解析查询上设置日期约束时出现问题

转载 作者:行者123 更新时间:2023-11-28 00:56:21 26 4
gpt4 key购买 nike

我正在尝试进行解析查询并通过 javascript API 对查询添加日期约束。

这是我正在查询的 Result 表/对象(在 parse.com 上): My "table": <code>Result</code>

Column                  Data type
objectId                StringcreatedDate             DateupdatedAt               DateobtainedPonts           NumberrelatedDriver           RelationrelatedTest             RelationACL                     ACLresultCeasesToBeValid   DatedidPassTheTest          Boolean

Some example data from resultCeasesToBeValid:

Example data from <code>resultCeasesToBeValid</code>

This is my goal: I want the query to give me a set of Result where today < resultCeasesToBeValid.

My problem is that I always recieve an Result array with .length = 0 when I'm trying to put date constraints on the query.

function IsApprovedAndHasValidResults(currentDriverObjectId) {

var Driver = Parse.Object.extend('Driver');
var currentDriverObject = new Driver();
currentDriverObject.id = currentDriverObjectId;

var queryResult = new Parse.Query(Result);

//set the constraints
queryResult.equalTo('relatedDriver', currentDriverObject); //this constraint works as expected

/****************************************************************************************************
*var today = new Date(); // "today" is as time of writing 3 oct 2014 *
* *
* //will give me a parseResults[] of .length=0: *
*queryResult.lessThan('resultCeasesToBeValid', today); *
* *
* //will give me a parseResults[] of .length=0: *
*queryResult.lessThan('resultCeasesToBeValid', { "__type": "Date", "iso": today.toISOString() }); *
* *
*****************************************************************************************************/

queryResult.find({
success: function (parseResults) {
// results is an array of Parse.Object.
/*when the code gets here parseResults array.lenght equals 0*/
},

error: function (error) {
// error is an instance of Parse.Error.
/*will never be here*/
}
});
}

其他开发者似乎也有同样的问题,user Abhishek suspects a bug 。根据Héctor Ramos (Parse) ,很久以前:“在 JavaScript 中处理日期时,应该使用 Date 对象,而不是字符串。”。显然这是行不通的!

我的代码在某些方面是错误的吗?

最佳答案

解决方法:

queryResult._where.resultCeasesToBeValid = {'$lt' :{ "__type": "Date", "iso": today}}};

_where 是一个“私有(private)属性(property)”,但我不会太依赖它。解析应该可以解决这个问题。

如果您可以[更改列类型],我建议将日期存储为 unix 时间戳以避免此类问题:

var timestamp = +new Date();
result.save({'resultCeasesToBeValid': timestamp});

关于javascript - 在解析查询上设置日期约束时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26179222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com