In Hoist does Hoist.data().save(obj) overwrite the object or merge it? - hoist

When I save an object into Hoist data when there is an existing _id does it merge the object or overwrite it?
For example:
Hoist.data("FOO").findById("a")
returns
{ _id: "a", hash: "moose", prop2: "asda" }
after
Hoist.data("FOO").save( { _id: "a", hash: "moo" })
is the result going to be
{ _id: "a", hash: "moo" } or { _id: "a", hash: "moo", prop2: "asda" }

It performs a merge on the existing object with the new object.
So the result will be { _id: "a", hash: "moo", prop2: "asda" }

Related

Group or cluster nodes with same node attribute with Cytoscape.js

I thought of doing it by passing position to all nodes but since the graph is formed when the user 'uploads a file', I can't have the position set earlier itself for this. Can you please suggest what to do here?
elements:[
"data": {"id":"a", "group":"g1", ....}
"data": {"id":"b", "group":"g1", ....}
"data": {"id":"c", "group":"g2", ....}
"data": {"id":"d", "group":"g3", ....}
.... ]
So, in this case, I'd like to see nodes with IDs "a" and "b" sort of form or stick closer and away from other nodes so as to show that these two belong to a single group.
Use parent field to group or cluster the nodes in your graph.
The field group can have two values 'nodes' or 'edges' which helps Cytoscape understand the element type.
In your case, we can do like:
elements = [
{ data: { id: "a", label: "a", group: "nodes", parent: "p1" } },
{ data: { id: "b", label: "b", group: "nodes", parent: "p1" } },
{ data: { id: "c", label: "c", group: "nodes", parent: "p2" } },
{ data: { id: "d", label: "d", group: "nodes", parent: "p2" } },
{ data: { id: "e", label: "e", group: "nodes", parent: "p2" } },
{ data: { id: "p1", label: "p1", group: "nodes" } },
{ data: { id: "p2", label: "p2", group: "nodes" } }
];
Screenshot of the arrangement achieved with the above snippet
Here, the ids a and b have p1 as parent so they will form a group and likewise, ids c, d and e will form a group under parent p2.
In order for the group node to be visible, we need to add a group: 'nodes' type object in the elements array.

Data type for an array of Object in realm - react-native realm

I'm using realm for Javascript using React-native
I want to generate a realm schema to hold an array of Object as this:
arrayOfObj:[{ key1:1111, key2:2222, key3:333 }]
What I have tried so far is using the mixed type in my schema
const mySchema = {
name: "mySchema",
properties: {
_id: "objectId",
arrOfObj: "mixed" //'have used mixed[] too but they all don't work
}
}
I have tried using mixed and also using mixed[] but when I try to insert the array of object i get the error: mySchema.arrOfObj must be of type 'mixed?[]', got 'object' ([object Object])].
Now, What is the correct data type for the array of object in realm?
const myScheme = {
name: "myScheme",
primaryKey: "_id",
properties: {
_id: "objectId",
_partition: "string",
name: "string",
tasks: "myData[]"
}
};
const myData = {
name: "myData",
primaryKey: "_id",
properties: {
_id: "objectId",
_partition: "string",
firstname: "string",
lastname: "string",
}
};

How To Check In Array Vuejs

I have object like this:
data() {
return {
headings: ['id','remark'],
rows: [
{
id: 1,
FirstName: 'Jhon',
LastName: 'Doe',
remark: 0
},
{
id: 2,
FirstName: 'Foo',
LastName: 'Bar',
remark: 1
}
]
}}
Is there away how do i check if key headings object exist in rows object.
Thanks and sorry for my bad english.
Yes, There's a way
function (row) {
return this.headings.reduce((res, heading) => res &= row.hasOwnProperty(heading), true)
}
This method should return true - if the row has the heading.

Need a version of _.where that includes the parent object key

What I have is an object like this:
formData = {
name: {
value: '',
valid: true
},
zip: {
value: 'ff',
valid: false
},
//...
}
And I want to filter this so that I only have the invalid objects. The problem with _.where and _.filter is that it returns an object like this:
[
0: {
value: '',
valid: false
},
1: {
value: '',
valid: false
}
]
I need the parent key names, name and zip to be included. How do I do this?
You are looking for _.pick() my friend.
https://lodash.com/docs#pick
_.pick(formData, function(value) {
return value.valid;
})
Good luck! :)

Find object in array of objects with same id

I have created classes
dojo.declare("UNIT",null,{
_id:'',
constructor:function(i){
this._id=i;
});
and
dojo.declare("ELEMENT", null, {
_id:'',
_unit_id:'',
constructor:function(u,i){
this._unit_id=u;
this._id=i;
});
I have array of Units and I want find one which have id like my element._unit_id. Hot to do this with Dojo ? I was looking in documentation examples but there is dojo.filter by I cannot pass argument . Can anybody help ?
You can use dojo.filter.E.g:
var units = [{
id: 1,
name: "aaaa"
},
{
id: 2,
name: "bbbb"
},
{
id: "2",
name: "cccc"
},
{
id: "3",
name: "dddd"
}];
var currentElementId = 2;
var filteredArr = dojo.filter(units, function(item) {
return item.id==currentElementId;
});
// do something with filtered array
}
Test page for you