简体   繁体   English

Node.js客户端与服务器-相同代码的结果不同

[英]Node.js client vs. server - same code different results

I have the following code on the client and on the server but it is giving me different results. 我在客户端和服务器上都有以下代码,但这给了我不同的结果。 The code on the client is correct. 客户端上的代码正确。

The code: 编码:

var Query = Parse.Object.extend("ParseTable");
var query = new Parse.Query(query);
query.equalTo("user", {
            __type: "Pointer",
            className: "_User",
            objectId: ID
        });
query.find().then(function (object) {
//where//object = [child] = [{user: child}]

var testObject = _.map(object, function (a) {
                console.log("inside testObject", a.get("user").id);
               //correctly shows 'someId' on both the server and client!

               return _.extend(_.find(a), {sTId: a.id}, {mId: a.get("user").id});});

               //where//testObject = [{user:child, sTId: 'abc123', mId: 'someId'}];
               console.log( _.first(testObject).mId);//'someId' on the client and 
               //'undefined' on the server});

I'm lost as to what I'm doing wrong and I have no one but the SO community to help. 我不知道自己在做什么错,除了SO社区,我没有人可以提供帮助。 Thanks. 谢谢。

The code above has been working for a long time and for reasons still unknown to me I can't get it to work. 上面的代码已经运行了很长时间,由于我仍然不知道的原因,我无法使其正常工作。 I decided to move on though by using the following solution to 'testObject' above. 我决定继续使用上面的'testObject'的以下解决方案。

var Query = Parse.Object.extend("ParseTable");
var query = new Parse.Query(query);
query.equalTo("user", {
            __type: "Pointer",
            className: "_User",
            objectId: ID
        });
query.first().then(function (object) {//notice first instead of find at the end of the query!

var testObject = {};
testObject.sTId = object.id;
testObject.mId = object.get("user").id;
testObject.user = object.get("user");
})

This ends up a better solution anyway, nice clean and easier to read! 无论如何,这最终是一个更好的解决方案,干净整洁,易于阅读!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM