简体   繁体   中英

Issue with parse.com user query example code - Uncaught ReferenceError: gender is not defined

Using parse.com and JavaScript SDK

The parse.com online help documents for querying a user https://www.parse.com/docs/js_guide#users-querying show this code

<script type="text/javascript">     
    Parse.initialize("xxxx", "xxxx");

var query = new Parse.Query(Parse.User);
    query.equalTo(gender, "female");  // find all the women
    query.find({
      success: function(women) {
        // Do stuff
      }
    });
 </script>

Exactly copied as below returns the following error:

Uncaught ReferenceError: gender is not defined

Uncaught ReferenceError: gender is not defined findfriends.html:46 (anonymous function)

Looking at this error on MDN it quotes

The ReferenceError object represents an error when a non-existent variable is referenced.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError

Have I missed something or is this an error in the parse.com documentation?

Parse data browser that shows the user object

在此处输入图片说明

I think it's a typo in the docs. That code expects there to be an in-scope variable called gender which isn't shown by the quoted code in the example. So either you're meant to have declared and initialized a gender variable, or (and this seems much more likely) it's just a typo and they meant to have gender in quotes:

query.equalTo("gender", "female");

This is borne out by other uses of equalTo , such as the example for basic queries :

var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
query.equalTo("playerName", "Dan Stemkoski");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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