this looks a very trivial query but I can't seem to make it work..
I am trying to get for instance an object that has locationName = "NYC" AND groupName = "Adults". I am trying to query using this code I found on Parse documentation:
var groupQuery = new Parse.Query("MyTable");
groupQuery.equalTo("group", groupName);
var locationQuery = new Parse.Query("MyTable");
locationQuery.equalTo("location", locationName);
var mainQuery = Parse.Query.or(locationQuery, groupQuery);
But I obviously fail because I am using Parse.Query.or instead what should have been Parse.Query.and which, for some reason doesn't exist...
Is there any alternative way to do it, for some reason I cannot find it on the documentation..
Cheers
Parse queries use and by default, which is why there is only a Parse.Query.or().
What you want to do can simply be achieved this way :
var mainQuery = new Parse.Query("MyTable");
mainQuery.equalTo("group", groupName);
mainQuery.equalTo("location", locationName);
Related
I am using QueryTask in ArcgGIS JS Api 3 and I want to execute multiple query in one call, I took a look at the documentation and I didn't find the possibility to do it
this is what I am using
arraygraphic.map(async (e)=>{
let query = new esri.tasks.Query();
query.where = "id = '"+id+"'";
query.outFields = ["*"];
let response = await queryTask.execute(query)
})
and this is what I want to do
let queryList=[];
arraygraphic.map(async (e)=>{
let query = new esri.tasks.Query();
query.where = "id = '"+id+"'";
query.outFields = ["*"];
queryList.push(query)
})
let response = await queryTask.execute(queryList)
any suggestion or help ?
thank you in advance
You can only have one "Query", but you can create a better where statement that searches for all the "id" in a single where statement.
Your where statement would end up looking something like:
id in (1,2,3,4).
You can find more details about the supported SQL under "Request parameters" at https://developers.arcgis.com/rest/services-reference/enterprise/query-feature-service-layer-.htm#GUID-62EE7495-8688-4BD0-B433-89F7E4476673
If you're not able to put all the queries in one SQL statement as Bjorn suggested (e.g. queries to multiple layers), then you can add the requests to an array and use promise.all to send all the requests
https://developers.arcgis.com/javascript/3/jssamples/query_deferred_list.html
using https://www.npmjs.com/package/slack-client
expects you to make an extra file just for the token and to get it you must do
process.env.SLACK_API_TOKEN
I don't like this approach of creating a file just for the sake of a token!
My code is server side, already in a directory that users cannot see so I would like to just write the token into the javascript as an object/string/array
I have so far failed with array
var token=[
'SLACK_TOKEN=xxxx'
, 'SLACK_CLIENT_ID=xxxx'
, 'SLACK_CLIENT_SECRET=xxxx'
];
and string
var token=
'SLACK_TOKEN=xxxx\n'
+ 'SLACK_CLIENT_ID=xxxx\n'
+ 'SLACK_CLIENT_SECRET=xxxx'
;
and object
var token={
SLACK_TOKEN:'xxxx'
, SLACK_CLIENT_ID:'xxxx'
, SLACK_CLIENT_SECRET:'xxxx'
};
Everyone else's apis just get you to put things like secret keys inside srings or objects like normal! How can I do this the normal way?
process.env.SLACK_API_TOKEN isn't a file, it's an environment variable. The advantage of keeping your API key there is that you can't accidentally commit it to version control. That said, the page you linked to makes it pretty clear that you don't have to use it:
var RtmClient = require('slack-client').RtmClient;
var token = process.env.SLACK_API_TOKEN || '';
var rtm = new RtmClient(token, {logLevel: 'debug'});
rtm.start();
Just set the token variable to your API token, then pass it as the first parameter to new RtmClient():
var RtmClient = require('slack-client').RtmClient;
var token = 'YOUR SLACK API TOKEN';
var rtm = new RtmClient(token, {logLevel: 'debug'});
rtm.start();
I'm trying to create a network using the vis.js library (http://visjs.org/) and django (the basic one - http://visjs.org/examples/network/basicUsage.html).
I need to pass data specifying the nodes of the network from django to javascript.
This is my views.py:
def create_network(request):
r=[]
for i in range(1,6):
d={}
d['id'] = i
d['label'] = 'Node ' + str(i)
r.append(d)
data = json.dumps(r)
return render(request, 'network.html', {"nodes":data})
This is the relevant part of my template:
n = {{ nodes }}
var nodes = new vis.DataSet(n);
When I run this, the {{nodes}} disappears and it simply becomes:
n =
var nodes = new vis.DataSet(n);
and I get unexpected token errors.
I'm relatively new to Django and javascript so sorry if this seems elemenatary. How would I fix this? Thanks.
Try the following:
var n = `{{ nodes|safe }}`;
var nodes = new vis.DataSet(n);
You may or may not need to add a jQuery.parseJSON() around the data before passing it into the vis.DataSet. I cannot say for sure because I have never used http://visjs.org/.
I'm using the code below to construct a JSON object that looks like this:
{"contacts":[{"provider":"Yahoo","firstName":"myname","lastName":"surname","nickname":"mynick","email":"myemail#hotmail.com","photoURL":"http://l.yimg.com/dh/ap/social/profile/profile_bxx.png"}]};
var data = {};
var contacts;
var gc = $.when(gigya.socialize.getContacts({callback: function(response){
data['contacts'] = response.contacts.asArray();
}}));
gc.done(function(response) {
contacts = data;
});
console.log(contacts);
When I pass the resulting contacts object to Google soy template, the JSON object doesn't seem well constructed.
With the code above, how do I construct a valid JSON object?
Thanks for helping out.
The object seems ok,
try using JOSN.stringify() example jsFiddle
or JSON.parse()
You can see in example, you can turn object into valid JSON and reverse into valid JS object.
Regarding your code
What do you get from response ?
And why do you use response here if you do not make use of it?
gc.done(function(response) {
contacts = data;
});
I would change this line EDITED
data['contacts'] = response.contacts.asArray();
to
contacts = JSON.parse(response.contacts);
and remove
gc.done(function(response) {
contacts = data;
});
I have this code in IndexedDB:
var request = objectStore.add({ entryType: entryType, entryDate: t});
Now I want to know the key of this record that was just added in. How do I do that?
I found this article, and this
code:
var data = {"bookName" : "Name", "price" : 100, "rating":"good"};
var request = objectStore.add(data);
request.onsuccess = function(event){
document.write("Saved with id ", event.result)
var key = event.result;
};
This does not work for me - key shows up as undefined. I think I am missing something basic here!
Go through this code
var data = {"bookName" : "Name", "price" : 100, "rating":"good"};
var request = objectStore.add(data);
request.onsuccess = function(event){
document.write("Saved with id ", event.result)
var key = event.target.result;
};
Hope this code will work to retrieve key of last inserted Record
The spec is written for user agent, not for developer. So it is confusing. Key generator is provided by the user agent.
Any event object that is received by onsuccess handler always have event.target.result. It is the key you are looking for. The key is auto generated if you don't provide it, assuming you set autoIncrement to true.
It is documented in Step 8: as follow:
The result of this algorithm is key.
The trick here is knowing how to search using phrases iteratively, until you land on what you need. I've never heard of IndexedDB before, but seem to have found what you want.
I put "IndexedDB" into a search engine and found this. That yielded the phrase "key generator", so I searched for that as well which led me to this and this.
The StackOverflow link discusses using UUIDs, which of course can be generated in JavaScript, and the last link appears to have examples to do what you want out of the box.
If you're using the idb Promise wrapper for IndexedDB then the new key is just the return value from the add() call:
import { openDB } from 'idb';
const db = await openDB(...);
const tx = db.transaction('mystore', 'readwrite');
const newId = await tx.store.add({ hello: 'world' });
await tx.done;
console.log(`Autogenerated unique key for new object is ${newId}`);
Remember of course, this will only work if you include autoIncrement: true in the options passed to createObjectStore().