Removing a Pointer From Array using ObjectId - javascript

Using Parse
I have an array of pointers, and I would like to remove an object from that array using only its objectId:
var rawProductObject = Parse.Object.extend("Product");
var product = new rawProductObject();
product.id = productObjectId;
userInventoryQuery = new Parse.Query("Inventory");
userInventoryQuery.equalTo("objectId", userInventory.id);
product.remove("owners", inventoryQuery)
However this does not work. I am not entirely sure about passing a query to the remove method, and not sure how to test it.
Any ideas?

Related

Find a key in Dictionary and access its value containing a KeyValue pair of Strings

I've got a dictionary of <long, List<KeyValuePair<string,string>> which I'm trying to access in JavaScript.
var data = new Dictionary<long, List<KeyValuePair<string, string>>>();
e.g: data would have Key:100, Value: Name, John
In Javascript,
I need to get all KeyValuePair<string,string>in data and add it into mu.Mappings using the long key.
ViewModel.Degrees.forEach(function(mu) {
mu.Mappings = ViewModel.MappingListResults.Keys(mu.ID)
.find((value => ViewModel.MappingListResults[key] === mu.ID)); //doesn't work
});
Any ideas or suggestions?

.map multiple entries from DB Query

I am trying to work out if you can have multiple "map objects" in the .set?
For example I have employees... I need one array per employee, or multiple map "key" objects maybe?
So maybe I need something like Map(0).get('UserID')
Map(1).get('UserID')
etc?
var map = new Map();
while not rs.eof
map.set('UniqueID', i)
.set('UserID', UserID)
.set('FullURL', URL)
.set('Age', 39)
.set('XXXX', XXX)
rs.movenext
wend
What I am looking to do is have multiple map objects i.e. 1 = UniqueID 1, 2 = UniqueID = 2.
Right now it brings back the last record.
You are setting the value against same variable again and again that's why in the end map shows you the last value. If you want to save an object against every unique value you can do it like that. You can use array if you want to instead of object. I hope this will solve your query.
Map overwrite the existing value that's what you are doing
var map1 = new Map();
var object={
UserID: 'UserID',
FullURL :'URL'};
map1.set('id', object);
map1.set('id', "2");
console.log(map1.get('id'))
Solution
var map = new Map();
var object = {};
while not rs.eof
object = {
UserID : UserID,
FullURL : URL
}
map.set(i, object )
rs.movenext
wend

How can a new data be added to firebase without the post keys?

I use the following code to add new data to firebase.
var postData = {
NSN: NSN,
ProductName: ProductName,
AssociatedContractNumber: AssociatedContractNumber,
ItemQuantity: ItemQuantity,
viewable_by: uid,
};
InventoryID = firebase.database().ref().child('Posts').push().key;
var updates = {};
updates['/Businesses/' + uid + '/Inventory/' + InventoryID] = postData;
what i want to do is to create a list of NSNs in child "NSN" without the uniquely generated post ids. But all the attempt to add just the NSN to child NSN keeps replace the old with the new NSN. so instead of something like 10 different NSNs i only got 1 which is the most recent one added.
I used this code initially
var postNSN = {
NSN: NSN,
};
updates['/Businesses/' + uid + '/National_Stock_Numbers/' + NSN] = postNSN;
the above only replaces the existing number with the new one instead of adding the new one
I also tried this
var NSNref = database.ref('/Businesses/' + uid + '/NSNs/')
NSNref.set({
NSN: NSN,
})
but nothing happens. How can I add a new NSN to child NSNs without the uniquely generated keys?
Just use push()
Say if you had and NSN object like
var NSN = { ... }
firebase.database().ref().child('Posts').push(NSN);
Doing this will always push the item to the end of your NSN array and firebase will take care creating unique key at the time of pushing.
Remember firebase don't know about arrays it only knows about objects.

how can i convert my data in javascript server side to json object and array?

i'm working with xpages and javascript server side i want to convert the fields in format json then i parse this dat and i put them in a grid,the problem is that these fields can contains values :one item or a list how can i convert them in json ?
this is my code :
this.getWFLog = function ()
{
var wfLoglines = [];
var line = "";
if (this.doc.hasItem (WF.LogActivityPS) == false) then
return ("");
var WFLogActivityPS = this.doc.getItem ("WF.LogActivityPS");
var WFActivityInPS = this.doc.getItem ("WFActivityInPS");
var WFActivityOutPS = this.doc.getItem ("WFActivityOutPS");
var WFLogDecisionPS = this.doc.getItem ("WF.LogDecisionPS");
var WFLogSubmitterPS = this.doc.getItem ("WF.LogSubmitterPS");
var WFLogCommentPS = this.doc.getItem ("WF.LogCommentPS");
var WFLogActivityDescPS = this.doc.getItem ("WF.LogActivityDescPS");
var Durr =((WFActivityOutPS-WFActivityInPS)/3600);
var json= {
"unid":"aa",
"Act":WFLogActivityPS,
"Fin":WFActivityOutPS,
"Durr":Durr,
"Decision":WFLogDecisionPS,
"Interv":WFLogSubmitterPS,
"Instruction":WFLogActivityDescPS,
"Comment":WFLogCommentPS
}
/*
*
* var wfdoc = new PSWorkflowDoc (document1, this);
histopry = wfdoc.getWFLog();
var getContact = JSON.parse(histopry );
*/ }
Careful. Your code is bleeding memory. Each Notes object you create (like the items) needs to be recycled after use calling .recycle().
There are a few ways you can go about it. The most radical would be to deploy the OpenNTF Domino API (ODA) which provides a handy document.toJson() function.
Less radical: create a helper bean and put code inside there. I would call a method with the document and an array of field names as parameter. This will allow you to loop through it.
Use the Json helper methods found in com.ibm.commons.util.io.json they will make sure all escaping is done properly. You need to decide if you really want arrays and objects mixed - especially if the same field can be one or the other in different documents. If you want them flat use item.getText(); otherwise use item.getValues() There's a good article by Jesse explaining more on JSON in XPages. Go check it out. Hope that helps.
If an input field contains several values that you want to transform into an array, use the split method :
var WFLogActivityPS = this.doc.getItem("WF.LogActivityPS").split(",")
// input : A,B,C --> result :["A","B","C"]

set array as value in json format in Javascript

I want to add array as json value.
Json format is as follows.
json_data = [
'name':'Testing'
'email':'TestEmail'
'links':[
'test#test.com',
'test#test1.com',
'test#test3.com']
]
How can I set value of 'links' in javascript like that?
I did as follows.
links_array = [];
links_array =['testing','test2'];
json_data.links = links_array;
I wanted to append these two string but couldn't.
Any help would be appreciate.
Assuming that the syntax of your example is correct, you can use the "push" method for arrays.
json_data = {
'name':'Testing',
'email':'TestEmail',
'links':[]
};
json_data.links.push("test1#test.com");
json_data.links.push("test2#test.com");
json_data.links.push("test3#test.com");
You have to make little changes to make it work.
First thing, You have to replace initial square brackets with curly one. By doing this your object will become JSON Literal - a key value pair.
Second thing, You have missed commas after 'name':'Testing' and 'email':'TestEmail'
Below will work perfectly:
var json_data = {
'name':'Testing',
'email':'TestEmail',
'links':[
'test#test.com',
'test#test1.com',
'test#test3.com']
}
In addition to push as mentioned by #giovannilobitos you can use concat and do it all in one go.
var json_data = {
'name':'Testing',
'email':'TestEmail',
'links':[
'test#test.com',
'test#test1.com',
'test#test3.com'
]
};
var links_array = ['testing','test2'];
json_data.links = json_data.links.concat(links_array);
console.log(json_data.links);
On MDN's array reference you can find a more complete list of how to modify arrays in JavaScript.

Categories

Resources