This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Adding a list of data from JSON to a page element  RSS feed

 
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, in my app, I will be making REST calls to the server that will send me back JSON of data. In one example a List of Users get returned froma query I run that I get friends of friends as a list. I want to display them on my page to look and act just like searching and adding friends on FaceBook. I could put it into an overlay and scrolling, but sometimes the List of Users I get, might be a list of Users attending an event, so not as large a list. I want that list of Users on the page itself in the middle content. I plan on making it very pretty and want to avoid using tables, but it might also end up needing pagination. I already have the serverside set up for pagination, I just pass the page number and number of users.

So my question is really the best approach to take in my Jquery javascript right after I have retreived the List of Users in JSON

One idea I had was to have a div or section that holds the placeholders for a user, and when I get the list of Users, loop through the users and clone the div for each user and show it in the content section in a list of items.
Another idea, is loop through the JSON and in the Javascript code append html. (I really don't want any HTML in my javascript code, but if that is the best way then so be it)
Third idea, there are table jquery plugins, but the look and feel of those plugins is very much table look and feel. I don't want columns. All the data for me I would put in one column with css to make it look cool.

Are there any other possible ideas I don't know about. (JSP page rendering on the serverside is not a solution for me) I only have one jsp page and that is the index to get the page started.

Thanks

Mark
 
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check out the jQuery tmpl plugin, which provides client-side templating.
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You might want to check out the jQuery tmpl plugin, which provides client-side templating.



Thanks Bear, I had looked at it before, but had forgotten about it. But reading about it it says that it is in beta and that it will not be worked on, that there are two other sort of alternatives and I can't tell but looks like competing ones between jsRender/jsViews and JQuery UI templates. I think the latter isn't completed yet.

Looking at some more stuff, Mustache and Handlebars looks promising, and from there ember.js looked like the style of webapp and approach that I am trying to achieve, but do I couple myself to too many outside JavaScript libraries. I mean I am coupled to JQuery now, but it is so prevalent that I don't see that as being a problem.

Thanks

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I see a library called backbone.js that looks like the same. Easy to update the html based on data domain brought back from the server as json ajax calls.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like I am choosing to use ICanHaz.js which uses Mustache templating.

Thanks

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Looks like I am choosing to use ICanHaz.js which uses Mustache templating.

Thanks

Mark



ICanHaz is actually a really cool templating api. They made it really easy and I like that I can create templates and partials to be added to templates, so a template inside another template.

These are the kind of libraries/tools out there that I am looking for. When they are real simple and easy to start using, then to me that is a big part of what makes one of these great.

Mark
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66789
168
IntelliJ IDE Java jQuery Mac Mac OS X
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!