How can I clone a Parse Query using the Javascript SDK on Parse Cloud Code?

自古美人都是妖i 提交于 2019-12-12 04:05:46

问题


I want to clone queries because it helps me structure my code better. But, when I try to clone an query, I get an error saying: Object [object Object] has no method 'skip'. Here's the code I've tried:

var _ = require('cloud/modules/lodash'); // custom lodash 4.0.0
...
var query = new Query('Class');

var clonedQuery = _.clone(query);        // .cloneDeep() doesn't work either
clonedQuery.skip(i);                     // succeeds in unit tests but fails on cloud code
var clonedQuery.first();

Note: The underscore _ is actually lodash 4.0.0 that I've manually bundled with my source code, not the cloud module from Parse.

It's not clear to my why this is failing — it's lodash doing the cloning here, so there should be no difference between my local unit testing node environment and the V8 Cloud Code environment.


EDIT: I was using Parse SDK 1.3.1 here. Solution is to upgrade. See below.


回答1:


_.clone() actually does work for Query in Parse SDK 1.6.14, but not on 1.3.1, which I was using. I didn't know that you can manage the Parse JS SDK version yourself using the parse jssdk tool!

The solution for me was simply to update the SDK. See the discussion here: https://github.com/ParsePlatform/Parse-SDK-JS/issues/171



来源:https://stackoverflow.com/questions/34888080/how-can-i-clone-a-parse-query-using-the-javascript-sdk-on-parse-cloud-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!