Parse & JS: Parse.Object

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

Storing data on Parse is built around a Parse.Object. Each Parse.Object contains key-value pairs of JSON-compatible data.

In this example, the key is foo and the value is bar.  In database, a key is also known as a column.

<!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>

<div>
    <div style='display:none' class='error'>
        <h1>Failed to connect to Parse database</h1>
    </div>

    <div style='display:none' class='success'>
        <h1>Successfully connected to parse database and insert a record</h1>
    </div>
</div>

<script>
    Parse.initialize('5d3sro43zBGj8AMYqWND5bFYMzAan7f5P5euZm7M', 'hlRZZqAylA7Fmah4Kk6ma8WK7QCT4cHrxjafnnkI');
    var TestObject = Parse.Object.extend('TestObject');
    var testObject = new TestObject();
    testObject.save({foo: 'bar'}, {
        success: function (object) {
            $('.success').show();
        },
        error: function (model, error) {
            $('.error').show();
        }
    });
</script>

</body>
</html>

Parse recommends that you NameYourClassesLikeThis and nameYourKeysLikeThis, just to keep your code looking pretty.

In this example, I have used TestObject as the class name and foo as the key.

To create a new subclass, use the Parse.Object.extend method as in:

var TestObject = Parse.Object.extend('TestObject');
Series Navigation<< Parse & JS: Objects and records
Parse & Javascript: Insert a record >>