jQuery to create items or items customized by jquery ?
Hello !
My question is more a good practices question than a technical one.
In fact, I have a server that asks a Database for items. The server returns to the browser the main HTML page with jquery and custom scripts. The main HTML page contains also the items (returned by the database) listed in a javascript var encoded in JSON (var truc = {"items": [{"title":"A",...},{...}]};).
There is NO AJAX process, all is given after a single request.
1/ The current behaviour is this one : After start, jquery takes the JSON var, reads it and creates <li></li> items in the DOM.
The li items have many properties, and I use .data() method to store those properties.
2/ Another way to do it : the server returns the HTML page but the <li></li> items are already here. jquery just analyses the DOM and put the .data() on the <li/>
3/ I have imagined this way : the server returns the HTML with the <li></li> items in the HTML page. The server also put the properties in the HTML. Like that : <li prop1="truc" prop2="machin"....>item</li>
I think this last idea is the one that permits to fully implement a MVC JS/jQuery script.
What do you think about this ? What way should I use ? I can be wrong on some points, do not hesitate to point me out the right solution !!
Thanks a lot !
K.