为什么查询运行会返回不正确的数据? [英] Why is Incorrect data being returned from query runs?

查看:57
本文介绍了为什么查询运行会返回不正确的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Parse.com和JavaScript SDK.

Using Parse.com and JavaScript SDK.

http://www.kudosoo.com/friendslist.html

在此处使用代码 http://jsfiddle.net/Dano007/LJ8rn/(只是作为参考,它将无法运行.

Using the code here http://jsfiddle.net/Dano007/LJ8rn/ (just for ref, it wont run).

我希望它返回用户单击用户名后在"friendName"变量中选择的用户的已上传徽章.

I'm expecting this to return the uploaded badges of the user that is selected in "friendName" variable after the user clicks on the username.

点击用户名时我会看到的是

What I'm seeing happen when clicking on the username, is that

  Username.push(object.get("uploadedBy"));  

返回的是他们刚刚单击的名称的用户名,而不是上传徽章的人的实际用户名.

is returning the username of the name they have just clicked and not the actual user name of the person that uploaded the badge.

因此,我得出结论,在我的JQuery/JavaScript代码中的某个地方,我想出了如何选择错误的元素.我想这一定与FriendName变量有关吗?但是我解决不了,这让我发疯了

Therefore I'm concluding that somewhere in my JQuery/JavaScript code I'm some how selecting the wrong element. I presume this must be to do with the FriendName variable? but I can't solve it and its driving me crazy

在屏幕截图中,您可以看到其a3aePaphBF应该在

In the screen shot you can see that its a3aePaphBF that should be returned in

<div id="FriendsStuffName"></div>

不是'A','dan'或'rob'

$(document).ready(function() {  
  $(document).on('click','.username', function (event) {
    event.preventDefault();
    friendName = $(this).text();
    console.log(friendName);
    friendFeed();
  });
});

/////////////////

/////////////////

var currentUser = Parse.User.current();
var myBadges = Parse.Object.extend("myBadges");


// Captures the input from the user and checks if the name already exists within the Db.
function friendFeed() {
  var friendName = $('#friendsearch').val();
  //console.log(friendName);
  var query = new Parse.Query(myBadges);

  new Parse.Query("myBadges").matchesQuery("uploadedBy", new Parse.Query("_User").equalTo("username", friendName));

  query.find({
    success: function (rules) {
               imageURLs = [];
               for (var i = 0; i < rules.length; i++) { 
                 var object = rules[i];
                 imageURLs.push(object.get("BadgeName"));
                 Username.push(object.get("uploadedBy"));
               }

               for(var j = 0; j < imageURLs.length; j++) {  
                 $('#FriendsStuff').append("<img class='images' src='" + imageURLs[j] + "'/>");
                 $('#FriendsStuffName').append("<div class='username'>'"+Username[j]+"'</div>");
               }
             },
    error: function(error) {
             //If the query is unsuccessful, report any errors
             alert("Error: " + error.code + " " + error.message);
            }
  });
}
</script>


<div id="imgs"></div>
<div id="username"></div>
<div id="container"></div>
<div id="FriendsStuff"></div>
<div id="FriendsStuffName"></div>
</body>
</html>

这是我的用户

推荐答案

这没有道理:

var query = new Parse.Query(myBadges);

new Parse.Query("myBadges").matchesQuery("uploadedBy", new Parse.Query("_User").equalTo("username", friendName));

首先,您要为"myBadges"创建查询,并将其分配给变量"query".然后,您要创建另一个查询,也用于"myBadges".此新查询未分配到任何地方.

First you are creating a query for "myBadges", assigning it to the variable "query". Then you are creating another query, also for "myBadges". This new query is not assigned anywhere.

运行"find"操作的查询是已分配给查询变量的查询.

The query that you are running the "find" operation on is the one that you have assigned to the query variable.

如果您期望第二行对第一行有任何影响,那么这很可能是错误的根源.

If you are expecting the second line, to have any influence on the first, then that is likely the source of your error.

尝试一下:

var query = new Parse.Query(myBadges);
query.matchesQuery("uploadedBy", new Parse.Query("_User").equalTo("username", friendName));
query.find({
    success: function (rules) {

这篇关于为什么查询运行会返回不正确的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆