Question

I have Javascript using Ajax to get a list of notes from Java (using the Play Framework). The notes have many properties, such as text, timestamp, attachments, users, etc. The notes are displayed truncated in li items. Click on them to see them in full.

I can't depend on their li representation for all the data the app will need. So my only solution is to pass full Note parameters from Java and 'recreate' the class in Javascript to cache these notes in an array. When li is clicked it spits out data from the Javascript array at the associated index. I would rather do this than make another call to the server to get the specific contents of the note.

Is this bad practice? It seems like there should be a more reliable, less 'code-reusing' way.

Était-ce utile?

La solution

There are many ways to approach the problem. I almost always opt to sending the raw data and let the client handle adding elements on the page. There are entire frameworks for this (Angular, Backbone, etc.) if what you're doing is more than trivial.

For the actual data serialization, I recommend JSON. Nearly everything supports it, and in my opinion it is much easier to deal with than XML.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top