Search code examples
javascriptjsonangularjsparse-platform

Can't parse/retrieve JSON using Angular


It seems I can't parse my JSON data from Parse into my web app. When I try alert my JSON data, it shows like this

[{
    "address1": "Test",
    "address2": "Test",
    "bathroom": "1",
    "bedroom": "1",
    "builtUpArea": "123",
    "cityId": "1",
    "countryId": "1",
    "description": "Test",
    "exclusive": true,
    "facingDirectionId": "1",
    "floorlevel": "1",
    "furnishTypeId": "1",
    "landArea": "123",
    "landAreaTypeId": "1",
    "name": "Test",
    "ownerContact": "Test",
    "ownerEmail": "Test",
    "ownerIc": "Test",
    "ownerName": "Test",
    "poscode": "123",
    "price": "Test",
    "purchaserId": "xZyLAKnCnXt",
    "remark": "Test",
    "stateId": "1",
    "statusId": "1",
    "tenureId": "1",
    "typeId": "1",
    "user": {
        "__type": "Pointer",
        "className": "_User",
        "objectId": "rquoctPnNz"
    },
    "objectId": "0nfSPUwgvm",
    "createdAt": "2015-04-10T02:16:54.509Z",
    "updatedAt": "2015-04-10T02:16:54.509Z"
}]

But nothing appear in my view page, only createdAt and updatedAt with "" symbol.

My code:

JavaScript:

var Property = Parse.Object.extend("Property");
        var user = Parse.User.current();
        var query = new Parse.Query(Property);
        query.equalTo("user", user);
        query.find({
            success: function(data) {
                alert(JSON.stringify(data));
                $scope.properties = data;
            },
            error: function(object, error) {
                alert(JSON.stringify(error));
            }
        });

HTML:

<tr ng-repeat="property in properties | filter:query">
                                        <td>{{property.name}}</td>
                                        <td>RM {{property.price}}</td>
                                        <td>{{property.createdAt}}</td>
                                        <td>{{property.updatedAt}}</td>
                                    </tr>

Solution

  • I already found the answer.

    $scope.properties = [];
    var Property = Parse.Object.extend("Property");
    var user = Parse.User.current();
    var query = new Parse.Query(Property);
    query.equalTo("user", user);
    query.find({
        success: function(data) {
            var index = 0;
            var Arrlen = results.length;
            for (index = 0; index < Arrlen; ++index) {
                var obj = results[index];
                $scope.properties.push({
                    objectId: obj.attributes.objectId,
                    name: obj.attributes.name,
                    price: obj.attributes.price,
                    createdAt: obj.createdAt,
                    updatedAt: obj.updatedAt
                });
            }
        },
        error: function(object, error) {
            alert(JSON.stringify(error));
        }
    });