Based on this question and answer, I've made this JSFiddle.
What I'm trying to do is to find a way to properly export / import JSON data to cytoscape.js.
I'm using JSON.stringify(cy.json()) to get JSON data from elements, and on the other hand I'm cleaning the cy area and using cy.add(text-input) to add the elements back.
I.e.: you can add a node, copy it's JSON data generated, then you can refresh the browser and paste the JSON data from node directly, tryng to add it to cy.
But I couldn't get this to work, and I can't really figure out where I'm wrong (probably using the cy.add function). Always geting both errors:
An element must be of type 'nodes' or 'edges'; you specified 'undefined'
Uncaught TypeError: Cannot read property 'single' of undefined
Any ideas?
Thanks in advance.
If you build from the source (or use 2.1 when released), you can use eles.jsons(), which gives an array of element JSONs. You're calling cy.json(), which gives the entire graph init options JSON -- which you can't pass to cy.add() or similar.
Alternatively to eles.jsons(), you can use the already existing ele.json() and build up an array yourself by iterating over the elements.
You also need to pass the objects to cy.add() etc. You can't pass a JSON string.
e.g.
cy.add( JSON.parse( jsonString ) )
Related
Let's jump straight to an example code:
create table test_json_table
(
data json not null
);
I can insert to the table like this:
const columns = { data: "{ some_json: 123 }" }; // notice that the data column is passed as string
await knex('test_json_table').insert(columns);
And get data from the table like this:
await knex('test_json_table').select();
// returns:
// [
// { data: { some_json: 123 } } // notice that the data is returned as parsed JavaScript object (not a string)
// ]
When inserting a row the JSON column needs to be passed as a serialised string. When retrieving the row, an already parsed object is returned.
This is creating quite a mess in the project. We are using TypeScript and would like to have the same type for inserts as for selects, but this makes it impossible. It'd be fine to either always have string or always object.
I found this topic being discussed at other places, so it looks like I am not alone in this (link, link). It seems like there is no way to convert the object to string automatically. Or I am missing something?
It'd be nice if knex provided a hook where we could manually serialise the object into string when inserting.
What would be the easiest way to achieve that? Is there any lightweight ORM with support for that? Or any other option?
You could try objection.js that allows you to declare certain columns to be marked as json attributes and those should be stringified automatically when inserting / updating their values https://vincit.github.io/objection.js/api/model/static-properties.html#static-jsonattributes
I haven't tried if it works with mysql though. I don't see any reason why it wouldn't.
I think the easiest way using jsonb data type. mysql json type
We prefer postgresql for this kind of problem at office, easier and solid database for your problem.
Well you could call your own function before inserting that converts all objects to string and call it every time before you insert.
You can probably wrap knex to do it automatically as well.
I'm building up a string in Meteor to drill down into my data from MongoDB.
My data looks like this:
Data
In my Meteor projects JavaScript I have built up the string like so:
const concentrationTier1 = MyCollection.findOne({_id: "85gh43tnb23v4"}).BILL.Sovereign.USD.Short.Low.High.N.ARGENTINA.IssueName00006.ARARGE5203E7;
console.log(concentrationTier1);
But now in my console it is returning the following:
Console
How would I add [Object] to my string to be able to display the next part of the data?
I have tried .[Object] .Object .0 and of course these didn't work.
Can any body help with this one?
Many thanks,
G
You would have to access that array element as in plain normal javascript, like this:
...IssueName00006.ARARGE5203E7[0].concentrationTier1
And the reason is your MongoDB query already returned a document, you're not querying in your database anymore so there's no need to use dot notation to access array elements.
How to add one to many relations in parse pointer, please check this screenshot:
It's a pointer and i can only add one pointer per row (one-to-one) i cant add one to many relationship to this using js it throws error.
{"code":111,"error":"invalid type for key members, expected *_User, but got array"}
And I don't wanna use parse 'Relation' type column due to querying 'Relation' is complicated.
If you want to have multiple-pointer column, just create array column and fill it with _User objects. Result will look like this and it will really be array of pointers:
[{"__type":"Pointer","className":"_User","objectId":"kIg9Kzzls9"},
{"__type":"Pointer","className":"_User","objectId":"TGCBZm52zW"},
{"__type":"Pointer","className":"_User","objectId":"YfGT9GvJs6"}]
Using include to get full objects in query also works, it is an array of pointers.
I have bump into this error before.
It is because the <Type> of your member column is already automatically set to *_User. If you try to set a many to many relation into the same column, it just don't work since the type are different.
You can solve the issue by manually deleting the column in your dashboard and set it in your code again.
Ok so I have a template in Play! that receives a List as a parameter:
#(actions : List[RecipientAction])
RecipientAction is just a regular case class with a couple of fields. Within the template, I have a <script> tag where I want to use D3 to make a line chart. Inside the script I want to populate a JavaScript array with objects that contain the properties stored in RecipientAction in order to use them for my line chart later. I currently have this code:
testArray2=[];
for(var i=0; i < #actions.length;i++){
testArray2[i]= {};
testArray2[i].eventAt= #actions(i).eventAt.toString();
testArray2[i].action= #actions(i).action.id;
}
When i run it, i get the error "not found: value i". This is because i is a client side variable while actions is a server side variable, so scala cannot find i. What would be the best way to work around this and successfully populate the array?
You need to create a JSON serializer for your RecipientAction, then you'll just be able to print the list as JSON in the template. Say it looks something like this..
import play.api.libs.json._
case class RecipientAction(id: Int, description: String)
object RecipientAction {
// Define a `Writes` for `RecipientAction`
implicit val writes: Writes[RecipientAction] = Json.writes[RecipientAction]
}
I used one of the JSON macros included with Play that will automatically create a Writes for a case class, since all we care about is printing the list.
Then in your template:
#(actions : List[RecipientAction])
#import play.api.libs.json.Json
<script type="text/javascript">
var testArray = #Html(Json.stringify(Json.toJson(actions)));
</script>
The definition of an implicit Writes is required so that Json.toJson knows how to convert the class to JSON. For more about Json serialization/deserialization see the documentation.
I have a grid which data is like this:
As you can see, there are some rows (0,1,2 and 3 objets) and inside each there are more objects. Please pay attention that there is an object called 'datosPersonales' ('personalData') with has inside more objets; nombre (name), apellido1(firstname) etc.
The problem arise when I try to get the data from one row:
var empleado = $("#GRID_empleado").jqGrid("getRowData",numRow);
What I get is and object with object inside but the the previously mentioned 'datosPersonales' objetc is not a 'father' of more objects. With an image (from firebug) is easier to understand:
I don't know why but instead of get 'datosPersonales' with his 'sons' I get them like these:
datosPersonales.nombre
datosPersonales.apellido1
datosPersonales.calle
etc
What is the way to get all / whole / raw data from a certain row of a grid or even of the complete grid?
I have tried with some parameters but I've not been successful.
What I want is to get for example the data of [3] in the first image.
Thanks in advance!
You don't posted any code which shows how you use jqGrid. Even such important options of jqGrid like datatype and loadonce are unknown. So I can only guess. I suppose that you create grid with subgrids to display all the data which you posted. I suppose that you use approach close to the way which I described here and here. In the way you can use either getLocalRow or .jqGrid("getGridParam", "userData") instead of getRowData. If you don't know the answers which I referenced I recommend you to read there.