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

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

问题描述

更新 - 赏金是帮助我解决这个问题,并允许代码根据用户输入过滤查询结果.如果通过 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)
                      );

它没有将正确的对象分配给 query.

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 函数中声明的:

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天全站免登陆