Parse & JS: Matching values with containedIn

This entry is part 20 of 25 in the series Parse & Javascript

If you want to retrieve objects matching several different values, you can use containedIn, providing an array of acceptable values.

This is often useful to replace multiple queries with a single query.

<!doctype html>
<head>
    <title>My Parse App</title>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
    <script type='text/javascript' src='http://www.parsecdn.com/js/parse-1.2.17.min.js'></script>
</head>

<body>

<script>
    Parse.initialize('5d3sro43zBGj8AMYqWND5bFYMzAan7f5P5euZm7M', 'hlRZZqAylA7Fmah4Kk6ma8WK7QCT4cHrxjafnnkI');
    var MoviObject = Parse.Object.extend('MoviObject');
    var moviObject = new MoviObject();

    var query = new Parse.Query(MoviObject);
    query.containedIn('releaseYear', [2013, 2012]);

    query.find(
            {
                success: function (moviObject) {
                    document.write('<h2>Movies released in 2012 and 2013:</h2>');
                    var i = moviObject.length;
                    i = i - 1;
                    for (i; i >= 0; i--) {
                        var title = moviObject[i].get('titleName');
                        document.write(title);
                        document.write('<br>');
                    }
                }
            }
    );
</script>

</body>
</html>
Try The Code

Take note how I have used the square bracket:

query.containedIn('releaseYear', [2013, 2012]);
Series Navigation<< Parse & JS: Sortable types
Parse & JS: Counting objects >>

Leave a comment

Leave a Reply