下划线 _.clone() 不适用于 Parse JS SDK 复合查询
Underscores _.clone() does not work with Parse JS SDK compound queries
我无法在 Parse Server v2.3.7(包括 Parse JS SDK v1.9.2)中对复合查询进行排序。我可以在原始查询中使用 ascending/descending 查询方法,但是当我克隆它时它们不再起作用。任何想法为什么这不起作用或者是否有更好的方法来克隆查询?
var firstQuery = new Parse.Query('Object');
firstQuery.equalTo('property', 1);
var secondQuery = new Parse.Query('Object');
secondQuery.equalTo('property', 2);
var query = Parse.Query.or(firstQuery, secondQuery);
query.descending('updatedAt');
// This works
var clonedQuery = _.clone(query);
clonedQuery.ascending('updatedAt');
// Throws error "clonedQuery.ascending is not a function"
继续这个问题:How can I clone a Parse Query using the Javascript SDK on Parse Cloud Code?
已更新
有一件事 Lodash.js 做了而 Underscore.js 没有。 Lodash.js 复制原型,而 Underscore.js 将 prototype
设置为 undefined
。要使其与 Underscore.js 一起使用,您需要手动复制原型:
var Parse = require('parse').Parse;
var _ = require('underscore');
var firstQuery = new Parse.Query('Object');
firstQuery.equalTo('property', 1);
var secondQuery = new Parse.Query('Object');
secondQuery.equalTo('property', 2);
var query = Parse.Query.or(firstQuery, secondQuery);
query.descending('updatedAt');
// This works
var clonedQuery = _.clone(query);
Object.setPrototypeOf(clonedQuery, Object.getPrototypeOf(query)); // This line is very important!
clonedQuery.ascending('updatedAt');
// This works too
我无法在 Parse Server v2.3.7(包括 Parse JS SDK v1.9.2)中对复合查询进行排序。我可以在原始查询中使用 ascending/descending 查询方法,但是当我克隆它时它们不再起作用。任何想法为什么这不起作用或者是否有更好的方法来克隆查询?
var firstQuery = new Parse.Query('Object');
firstQuery.equalTo('property', 1);
var secondQuery = new Parse.Query('Object');
secondQuery.equalTo('property', 2);
var query = Parse.Query.or(firstQuery, secondQuery);
query.descending('updatedAt');
// This works
var clonedQuery = _.clone(query);
clonedQuery.ascending('updatedAt');
// Throws error "clonedQuery.ascending is not a function"
继续这个问题:How can I clone a Parse Query using the Javascript SDK on Parse Cloud Code?
已更新
有一件事 Lodash.js 做了而 Underscore.js 没有。 Lodash.js 复制原型,而 Underscore.js 将 prototype
设置为 undefined
。要使其与 Underscore.js 一起使用,您需要手动复制原型:
var Parse = require('parse').Parse;
var _ = require('underscore');
var firstQuery = new Parse.Query('Object');
firstQuery.equalTo('property', 1);
var secondQuery = new Parse.Query('Object');
secondQuery.equalTo('property', 2);
var query = Parse.Query.or(firstQuery, secondQuery);
query.descending('updatedAt');
// This works
var clonedQuery = _.clone(query);
Object.setPrototypeOf(clonedQuery, Object.getPrototypeOf(query)); // This line is very important!
clonedQuery.ascending('updatedAt');
// This works too