Why does this query return all query results and not just those matched with users name?

前端 未结 1 926
情歌与酒
情歌与酒 2020-12-18 17:37

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

相关标签:
1条回答
  • 2020-12-18 17:52

    Your code states:

    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.

    I believe it should be

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

    Update:

    Other problems show up here, with the friendName variable.

    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.

    Prefer a parameter:

    $(document).ready(function () {
        $(document).on('click', '.username', function (event) {
            event.preventDefault();
            friendFeed($(this).text());
        });
    });
    
    function friendFeed(friendName) {
        //var friendName = $('#friendsearch').val();
        ...
    }
    
    0 讨论(0)
提交回复
热议问题