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) {
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) {
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?
source
share