如何将自定义属性的值推送到Parse数据库

时间:2014-12-18 15:06:38

标签: javascript angularjs parse-platform

尽管Parse.User类应该是Object类的扩展,但我无法在Parse数据浏览器上看到记录的更新。这可能是因为调用Parse.User.current()实际上并不是对数据库的调用吗?

.controller('SignAddrCtrl', ['$scope','$state','geocode','$rootScope','Address',
    function($scope, $state, geocode, $rootScope, Address) {

    $scope.address = {
        userId: {"__type":"Pointer","className":"_User","objectId":$rootScope.user.id}
    };

    $scope.create = function() {
        geocode.getCoords($scope.address.address1, $scope.address.zipCode)
        .success(function(data) {

            var lat = data.results[0].geometry.location.lat;
            var lng = data.results[0].geometry.location.lng;

            $scope.address.location = {
                "__type":"GeoPoint","latitude":lat,"longitude":lng
            };

            Address.create($scope.address)
            .success(function(data) {
                console.log(data.objectId); // this works
                var activeAddress = {
                    "__type":"Pointer", "className":"Address", "objectId":data.objectId
                }
                 // HERE IS THE ISSUE
                Parse.User.current().set('activeAddress',activeAddress);
                Parse.User.current().get('activeAddress'); // this works

            });

        });
    };
}])

在我的User类上为自定义属性执行更新操作的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

如果您需要使用数据库中的最新数据更新对象,则应该获取它。

myObject.fetch({
  success: function(myObject) {
    // Fetch successful
  },
  error: function(myObject, error) {
    // Error handling
  }
});