Getting Json from the Server and displaying it in the grid is relatively straight forward. In the application (http://pssnet.com/~devone/extjs3/loadSelection5.html) I generate a dynamic grid datastore. I need to send this to the Server for further processing.
If there is a way to convert the data store to json, I can strigyfy it and send it a param...as in jQuery.
Otherthan looping through the whole datastore to build json, there seems no methods.
Thank you.
(I can guarantee that the following applies to Ext > 2.3)
Because Ext.data.Store stores an array of Ext.data.Record objects, it has no direct access to the underlying data (Ext.data.Record encapsulates the data), so, indeed, there's no direct way to do it. But Ext.data.Record itself has a public property called "data" (an object with the field:value properties), which you can collect into an array (e.g. using the Ext.data.Store#each method) and then encode with Ext.encode() to "stringify" it.
Related
So I read somewhere that storing object into Redis using pickle (Python) could result in malicious code running (It being binary data)
In context to this, I want to store an array of object created by end-user as cache in Redis. The best solution that I have come up with is to stringify the object and create an array of strings.
My concern is since the object will be created by the end-user is it safe to use the aforementioned method of converting JSON to BSON or work with stringify with Redis (I am using javascript)?
Data Eg:
[{"fname": "temp.txt", "size": 50, "type":"pdf", "mt": "Timestamp"},{..},...]
PS: I will be using javascript and not python. Also, any alternate solution which is faster/safer is welcomed.
I'm trying to get 2D array from javascript to spring boot function in Java and it doesn't work. Here is my code.
Is there someone who knows how to do it? 1D array isn't problem to do like this. Is it possible with this form or should I use something else?
By the way your data object is constructed:
data: {matrixA: ...}
the backend is expecting an object with a field matrixA, instead of a matrix. In your controller, define a class to encapsulate the matrixA and use that as a RequestParam.
Moreover, you can always inspect the actual request being sent in browser's developer tools, network tab.
Secondly, javascript arrays can be automatically mapped to lists in Java by (almost) all serialization libraries, so you could use a List<List<Integer>> to map your matrix if that is more convenient.
If you don't want to encapsulate your request in an object with the field matrixA, you could send matrixA directly in the data field: data: matrixA, and expect a List<List> in the controller.
Currently, my website is using a Mongo.Collection to hold data submitted from another site. Strings are sent over through HTTP methods and packed into the collection afterward. However, this collection now needs to support storing larger files, but still needs to hold the data already stored, so I've been looking into converting the collection into GridFS. Is there a way to attach the data onto empty files as metadata, or is the conversion more convoluted than this?
I'm ending up having to do hacks to convert 'true' to just true and it's creating code smell.
Is there a library like https://github.com/thephpleague/fractal that allows me to transform my response into the types I need?
In cases like this it's almost always better to fix the API to return data in a usable format rather than trying to post-process the result on the client.
In your case there are several routes you could take:
Store the list as a JSON string directly in the database.
This means you don't have to do any processing on the server and can just return it 'as is'. However you lose the ability to do queries on the data directly and need to resort to things like LIKE and string operations.
Store the data relationally, and process it on the server to turn it into JSON
Here you retain the ability to do queries on your data, but you may need to do several queries to get all the data you need and then connect it on the server. (eg. you would do one SELECT on the user table to get a user, and then you would need to do another SELECT on the friends table where the userid matches your first user. You would then need to merge these results to create your JSON.) This is usually the best way to do it.
You can also turn the result into JSON directly inside the database engine using a user defined function. For example using https://github.com/mysqludf/lib_mysqludf_json#readme
This is somewhat similar to 2, but it ties your stored procs to the JSON format.
I'm trying to send an object graph from Python to JavaScript running in a browser, and I was wondering whether there is a pair of ready-to-use libraries for handling serialization on the Python side and deserialization on the JavaScript side. JSON does not support object references out of the box, the docs for JS-YAML say it's not production-ready in a browser environment, and I didn't find anything for XML. Any suggestions?
edit: Here's an example for what I mean by "JSON does not support object references out of the box": I have a shop database with products and orders and a many-to-many relationship between them. If I put a bunch of orders into the Python JSON serializer, the result will contain multiple serializations (copies) of each product, because the JSON serializer has no way of saying, "I've serialized this product already, so I'll just insert a reference to it". So I put the result on the wire and deserialize it on the client, and now I have multiple JavaScript objects representing the same product, which is bad.
how about jsonpickle? JS is awesome with json out of box, adding json pickling in python is the missing link:
jsonpickle