I am performing multi-level inner queries but it gives me a 400 Bad Request for the line with the find() function, what have I done wrong?
var EducationVenue = Parse.Object.extend("EducationVenue");
var EducationVenueRoom = Parse.Object.extend("EducationVenueRoom");
var EducationLessonSet = Parse.Object.extend("EducationLessonSet");
var EducationLesson = Parse.Object.extend("EducationLesson");
var eduLessonSetQuery = new Parse.Query(EducationLessonSet);
eduLessonSetQuery.matchesQuery("educationListingId", eduListingQuery);
var eduLessonQuery = new Parse.Query(EducationLesson);
eduLessonQuery.matchesQuery("educationLessonSetId", eduLessonSetQuery);
eduLessonQuery.include('educationVenueRoomId.educationVenueId');
$scope.coursesAtLocations = [];
eduLessonQuery.find({
success: function(coursesAtLocations) {
for (var i = 0; i < coursesAtLocations.length; i++) {
$scope.coursesAtLocations.push(coursesAtLocations[i]);
console.log('c at loc' + coursesAtLocations[i]);
}
}
});
The reason for this is "query has too many nested queries", what is the more convenient workaround for this?
Related
There is a website that has multiple requests and responses , one of them is like this:
https://xxx.hhhh.com/someResult?Type=customsectors&jsoncallback=
and i know how the JS callback function is being called.
i need to know that whether:
is there any way to modify that JS file ?
OR
is it possible to manually write callback function inside query string like this:
https://xxx.hhhh.com/someResult?Type=customsectors&jsoncallback=
{
function (ojr) {
var res = new Object();
res.symbolinfo = RlcServices.PopulateSymbolInfo(ojr.symbolinfo, appendFullDetails);
res.symbolinfo.IsAti = res.symbolinfo.NSCCode.indexOf("IRO2") >= 0 || res.symbolinfo.NSCCode.indexOf("IRO4") >= 0;
var queueInfo = [];
for (var i = 0; i < ojr.symbolqueue.Value.length; i++) {
queueInfo[i] = {};
queueInfo[i].BestBuyLimitPrice = ojr.symbolqueue.Value[i].BestBuyPrice;
queueInfo[i].BestSellLimitPrice = ojr.symbolqueue.Value[i].BestSellPrice;
queueInfo[i].BestBuyLimitQuantity = ojr.symbolqueue.Value[i].BestBuyQuantity;
queueInfo[i].BestSellLimitQuantity = ojr.symbolqueue.Value[i].BestSellQuantity;
queueInfo[i].NumberOfOrdersAtBestBuy = ojr.symbolqueue.Value[i].NoBestBuy;
queueInfo[i].NumberOfOrdersAtBestSell = ojr.symbolqueue.Value[i].NoBestSell;
queueInfo[i].NSCCode = ojr.symbolqueue.Value[i].NSCCode;
queueInfo[i].Place = ojr.symbolqueue.Value[i].Place;
}
res.symbolqueue = queueInfo;
fnCallback(res);
}
}
and i need to change the for loop number here. is it possible or i can't do anything and:
"It is what it is !!!"?
I am trying to do sync call using tableau.
var checkLen = $s_filter_i.length;
for (i = 0; i < checkLen; i++) {
var filterValfscr = $s_filter_i[i].VALUE;
Send_Tablo(filterValfscr);
}
When call this function Send_Tablo(filterValfscr) it runs the below code.
But the problem is before I get response form getSummaryDataAsync() it comes out of the function recalls Send_Tablo(filterValfscr) again I get the latest request data instead of first data request.
function Send_Tablo() {
var filter_indx = JSON.parse(window.localStorage.getItem('filter_indx'));
var arry = [];
for (var i = 0; i < filter_indx.s_filter_i.length; i++) {
Attr_lab_name = filter_indx.s_filter_i[i].ATTRIBUTELABEL;
arry.push(filter_indx.s_filter_i[i].VALUE);
}
currentViz.getWorkbook().changeParameterValueAsync('Attribute_Label', filterValfscr, Attr_lab_name, arry);
alert(filterValfscr);
var fScr_data;
sheet = currentViz.getWorkbook().getActiveSheet();
sheet.getSummaryDataAsync(options).then(function (t) {
data = t.getData();
console.log("Data", data);
frscr_demo();
});
function frscr_demo() {
//var fScr_data;
currentViz.getWorkbook().getActiveSheet().applyFilterAsync(Attr_lab_name, arry, tableau.FilterUpdateType.REPLACE);
sheet = currentViz.getWorkbook().getActiveSheet();
sheet.getSummaryDataAsync(options).then(function (t) {
fScr_data = t.getData();
console.log("FSCR", fScr_data);
var aa = $(fScr_data).length;
});
}
}
What I am try to achieve is Send_Tablo() should run all the Async function first before running the second iteration of Send_Tablo() from the for loop.
Do let me known what I am doing wrong? Thanks in advance.
I have the code below. Basically I have 3 nested parse queries. One is getting a number of "followers" and for each follower I am getting a number of "ideas" and for each idea I would like to get that idea creator's name (a user in the user table).
The first two nested queries work but then when i try to get the name of the user (the creator of the idea), that last nested query DOES NOT execute in order. That query is skipped, and then it is executed later in the code. Why is this happening please?
var iMax = 20;
var jMax = 10;
var IdeaList = new Array();
var IdeaListCounter = 0;
var myuser = Parse.User.current();
var Followers = new Parse.Query("Followers");
Followers.equalTo("Source_User",{__type: "Pointer",className: "_User",objectId: myuser.id});
Followers.find({
success: function(results) {
for (var i = 0; i < results.length; i++) {
var object = results[i];
var Ideas = new Parse.Query("Ideas");
Ideas.equalTo("objectId_User", {__type: "Pointer",className: "_User",objectId: object.get('Destination_User').id});
Ideas.find({
success: function(results2) {
for (i=0;i<iMax;i++) {
IdeaList[i]=new Array();
for (j=0;j<jMax;j++) {
IdeaList[i][j]=0;
}
}
for (var j = 0; j < results2.length; j++) {
var object2 = results2[j];
var ideausername2 = "";
IdeaListCounter++;
var ideausername = new Parse.Query("User");
ideausername.equalTo("objectId",object2.get('objectId_User').id);
ideausername.first({
success: function(ideausernameresult) {
ideausername2 = ideausernameresult.get("name");
}
});
IdeaList[IdeaListCounter,0] = object2.get('objectId_User').id + " " + ideausername2; //sourceuser
IdeaList[IdeaListCounter,1] = object2.get('IdeaText'); //text
IdeaList[IdeaListCounter,2] = object2.get('IdeaImage'); //image
IdeaList[IdeaListCounter,3] = object2.get('IdeaLikes'); //likes
IdeaList[IdeaListCounter,4] = object2.get('IdeaReport'); //reports
Your nested query is asynchronous.
Check out the answer at the following for guidance:
Nested queries using javascript in cloud code (Parse.com)
Im trying to use multiple deferred with jquery $.when but so far no luck, this is my code:
var req = $.when(db.count('items'),db.values('items'),db.get('config', 1));
req.done(function(count,r,config) {
var currency = config.currency;
if(count > 0){
var n = r.length;
for (var i = 0; i < n; i++) {
var id = r[i].id;
var itemId = r[i].itemId;
console.log('ID: '+id+' itemID: '+itemId+' Currency: '+currency);
}
}
});
My sample isn't working so hope you guys can help me, I searched everywhere for a solution. Thanks
I see. I will see how I could implement jquery deferred list. Although ydn-db promise has done, fail and them, etc, it is not $.Deferred instance. An adaptor approach is require.
Currently, use transaction as follow:
var results = {};
var tx_req = db.run(function(tx_db) {
tx_db.count('items').done(function(x) {
results.count = x;
});
tx_db.values('items').done(function(x) {
results.values = x;
});
tx_db.get('config', 1).done(function(x) {
results.config = x;
});
}, ['items', 'config'], 'readonly');
req.done(function() {
var count = results.count;
var r = results.values;
var config = results.config;
var currency = config.currency;
if(count > 0){
var n = r.length;
for (var i = 0; i < n; i++) {
var id = r[i].id;
var itemId = r[i].itemId;
console.log('ID: '+id+' itemID: '+itemId+' Currency: '+currency);
}
}
results = null;
});
It is a bit messy, but more efficient because all three query run in a single transaction.
EDIT:
Just need to add promise() method that return an object having done, fail and progress functions. Should be doable without much overhead. Basically you can do an adaptor like:
var wrap = function(req) {
req.promise = function() {
return req; // Note: req has done, fail and progress functions.
// however, jquery api demand promise to return a new deferred.
}
return req;
}
$.when(wrap(db.count('items')),wrap(db.values('items')),wrap(db.get('config', 1)));
Here is complete code in jsfiddle.
EDIT:
From release 0.8.1, promise method is added to request object and wrapping is no longer needed. Example.
I'm trying to parse the json grabbed from here. Basically what I do is iterate over the items, sort them, then display them. But I get an error saying data.data.children[i] is undefined.
I can't think why it's doing it though?
var json = 'http://www.reddit.com/reddits/mine/.json';
GM_xmlhttpRequest({
method: "GET",
url: json,
onload: reddits
});
function reddits(response){
var txt = response.responseText;
var data;
var suggested = document.getElementById('suggested-reddits');
if(window.JSON && JSON.parse){
data = JSON.parse(txt);
}
else{
data = eval("("+txt+")");
}
suggested.innerHTML += '<span>reddits you\'re subscribed to </span> <ul id="rsub"></ul>';
GM_addStyle('#rsub{width: 500px;}');
var reddits = new Array();
var rsub = document.getElementById('rsub');
for(i = 0; i <= data.data.children.length; i++){
var r = data.data.children[i].data.display_name;
reddits.push(r);
}
sort(reddits);
for(i = 0; i <= reddits.length; i++){
rsub.innerHTML += '<li>' + reddits[i] + '</li>';
}
}
for(i = 0; i <= data.data.children.length; i++){
var r = data.data.children[i].data.display_name;
reddits.push(r);
}
Clear problem is in the for statement. Change the i <= data.data.children.length to i < data.data.children.length. Note the inequality change.
Since arrays in Javascript are 0-indexed, the element at i = data.data.children.length does not exist.
You should probably do the same things for the reddits.length loop.