为什么此查询会返回所有查询结果,而不仅仅是那些与用户名匹配的结果? [英] Why does this query return all query results and not just those matched with users name?

查看:114
本文介绍了为什么此查询会返回所有查询结果,而不仅仅是那些与用户名匹配的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新 - 赏金是帮助我解决此问题并允许代码根据用户输入过滤回查询结果。如果通过 jfiddle 帮助完整代码可以共享

UPDATE - The bounty is to help me resolve this issue and allow the code to filter back query results based on the user input. Full code can be shared if it helps via jfiddle

我无法理解为什么下面的脚本将所有结果返回给用户,因为它只应返回friendName上传的myBadges类的结果。

I can't understand why the script below is returning all results to the user when it should only return the results from the "myBadges" class that have been uploaded by "friendName".

也许它仍然可以用指针使用objectId而不是实际名称dave关联到?

Maybe its something to still do with pointers using the objectId and not the actual name "dave" associated to the?

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

仍然卡住就此而言。关注我的原始问题:

为什么在切换查询的类后查询不返回结果?

Still stuck on this. Following my orignal question from:
Why does the query not return results after I switch the class it queries?

<script?
$(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>


推荐答案

您的代码状态:

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

它没有将正确的对象分配给查询

It does not assign the correct object to query.

我认为它应该是

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



更新:



其他问题出现在这里,使用 friendName 变量。

这是在 friendFeed function:

This is declared inside your friendFeed function:

function friendFeed() {
    var friendName = $('#friendsearch').val();
    ...
}

这样,外面无法访问功能。另外,您在此处设置了一个值,但尝试在事件中覆盖它。

In this way, it is not accessible outside the function. Plus, you set a value here, but try to overwrite it on your event.

首选参数:

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

function friendFeed(friendName) {
    //var friendName = $('#friendsearch').val();
    ...
}

这篇关于为什么此查询会返回所有查询结果,而不仅仅是那些与用户名匹配的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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