The request works first but does not find

I use angularjs and parse.comto query three members using spotlight = true.

When I use first, it will find it, but when I use find with limit(3), it will not find anything. I even deleted limit(3)and still nothing. I searched on the Internet, having tried several things that I found, the result is still zero.

    app.controller('spotlightCtrl', function($scope, $q) {

    $scope.sl = {};
    $scope.slmemid = "";

    Parse.initialize("xxx", "xxx");
    Parse.serverURL = 'https://parseapi.back4app.com';
    var ArticleDfd = $q.defer();
    var members = Parse.Object.extend('members');
    var query = new Parse.Query(members);
    query.equalTo("spotlight", true);
        query.first().then(function (data) {
 //query.find().then(function (data) {      -----this find does not return results.
            ArticleDfd.resolve(data);
            }, function (error) {
            ArticleDfd.reject(data);
             console.log(error);
            });
            ArticleDfd.promise
            .then(function (article) {
                $scope.sl = article.attributes;
                $scope.slmemid = article.id;
              console.log(article);
            })
            .catch(function (error) {
                //do something with the error
             console.log(error);
            });

});

We are looking for a way to do it right. I have found a job. I use the skip () function and create three controllers.

app.controller('spotlightCtrl1', function($scope, $q) {.....
    .....
    query.equalTo("spotlight", true);
    query.first().then(function (data) {

app.controller('spotlightCtrl2', function($scope, $q) {......
    .....
    query.equalTo("spotlight", true).skip(1);
    query.first().then(function (data) {...

app.controller('spotlightCtrl3', function($scope, $q) {......
    .....
    query.equalTo("spotlight", true).skip(2);
    query.first().then(function (data) {....

I think it will be slower. still want to know the correct code?

+4
source share
1 answer

Stackoverflow back4app.com ( ).

REST. "" (#gt). stackoverflow. " https://parseapi.back4app.com/ https://api.parse.com/1/" , Google Groups.

$http({
      method: 'GET',
      url: ' https://parseapi.back4app.com/classes/Events',
      headers: {
        'X-Parse-Application-Id' : 'xxxx',
        'X-Parse-REST-API-Key' : 'xxxx',
        'Content-Type' : 'application/json'
      },
      params:  { 
                 where: {
                     'Luncheon': true,
                     'eventDate':{'$gt': {
                     "__type":"Date", "iso": currentTime
                        }
                     }
                 },
                 order: 'eventDate',
                 limit: 2
              }
    }).then(function successCallback(response) {
        // this callback will be called asynchronously
        // when the response is available
        $scope.events = response.data.results;

      }, function errorCallback(response) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
        console.log(response);
  });

, , .

0

Source: https://habr.com/ru/post/1650443/


All Articles