That's really nice Kurt - that was a feature that was requested today,
as I presented jQuery at the Ajax Experience. Something like this is
definitely important, and I feel that we'll start to see more
templating solutions pop up.
--John
On 10/24/06, Kurt Mackey <[EMAIL PROTECTED]> wrote:
> In my perfect world, all data I get from a server will be JSON, and I
> can format it how I please. Doing that with jQuery is somewhat verbose
> at the moment, leaving me with awesome code like this:
>
> var headlines = $(Journals.HeadlinesContainer);
> for(i in json){
> var li = $.LI({ Class: json[i].ContainerFileName });
> var a = $.A().href(json[i].Url);
>
> headlines.append(li.append(a.append($.TEXT(json[i].Title))));
> }
>
> The Yahoo UI extensions (Jack Slocum rocks) have a neat Template class
> that makes this a little easier, so I went ahead and jQueryfied it.
>
> My function now looks like:
>
> $(Journals.HeadlinesContainer).appendTemplated(
> '<li class="#{ContainerFileName}"><a
> href="#{Url}">#{Title}</a></li>',
> json
> );
>
> Which is way nicer, IMO. :)
>
> Have a look at the demo here:
> http://mubble.net/jquery/jquery.template.html
>
> The template plugin itself is here:
> http://mubble.net/jquery/jquery.template.js
>
> For large results sets, you can pass a { 'compiled' : true } to the
> appendTemplated function, which turns the template into a javascript
> function rather than running a regex on every iteration.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/