How to refresh data using parse and swift?

Refresh ng-repeat rows when new data is added to source using parse.com

  • I have this AngularJS controller wich fetches data from a class I have created on parse.com app.controller('dataCtrl', function($scope) { var MarketingData = Parse.Object.extend('MarketingData'); var query = new Parse.Query(MarketingData); query.find({ success: function(results) { $scope.$apply(function() { $scope.resultData = results.map(function(obj) { return { startDate: obj.get('StartDate'), endDate: obj.get('EndDate'), investment: obj.get('Investment'), format: obj.get('Format'), partner: obj.get('Partner'), purpose: obj.get('Purpose') } }); }); } }); }); Together with this HTML <tr ng-repeat="x in resultData"> <td>{{x.startDate | date: 'yyyy-MM-dd'}}</td> <td>{{x.endDate | date: 'yyyy-MM-dd'}}</td> <td>{{x.investment}}</td> <td>{{x.format}}</td> <td>{{x.partner}}</td> <td>{{x.purpose}}</td> </tr> How can I bind a button to refresh the rows with new data (new rows)? I'm fairly new to both parse.com and AngularJS. Thank's

  • Answer:

    You should put your code to get data inside a function, then call that function when you press on the refresh button. I'd write it like it : app.controller('dataCtrl', function($scope) { function getData() { var MarketingData = Parse.Object.extend('MarketingData'); var query = new Parse.Query(MarketingData); query.find({ success: function(results) { $scope.$apply(function() { $scope.resultData = results.map(....); }); }); }); }; getData(); //Get data on launch $scope.refreshData = function() { getData(); } }); In the HTML, just add : <button value="Refresh" ng-click="getData()"></button>

David at Stack Overflow Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.