The other option to prevent writing things more than once is to add
the table into the original page via async calls initially, rather
than it being generated by kid first. That way you only have one
point of change.
That is what I'm currently doing for an app I'm developing. My index
template is a lot of empty divs that get populated via mochikit's DOM
manipulation and spiffy node generation.
Lee
On 02/11/05, Ronald Jaramillo <[EMAIL PROTECTED]> wrote:
>
> Heya =)
> I'm not fan of javascript, but working the DOM with MochiKit is not
> shabby at all.
> I wrote a simple table widget for CatWalk which can be used in other
> settings (it only depends on MochiKit).
> The widget renders a table based on javascript data structures
> (JSON), which TG makes trivial to deliver.
> You can read the (meagre) docs and check some samples @ http://
> www.checkandshare.com/static/js/widgetUsage.html
> Cheers,
> Ronald
>
> On Nov 2, 2005, at 1:43 AM, wavy davy wrote:
>
> >
> > Heya all.
> >
> > First post, cracking good framework, am much taken with it. It Does
> > Things Right(TM). Props, Kevin et al.
> >
> > I have a question of best practice in TurboGears:
> >
> > I've got a method (Root.page()), w/kid template (page.kid) that spits
> > out a full html document to the browser. I then want to update a
> > section of that page using AJAX-funkyness. In my case I want to
> > AJAX-update the contents of a table depending on user choices.
> >
> > AFAICS, the recomended way of doing this seems to be request a JSON
> > data structure, then construct the table out of that in javascript. I
> > don't like this because you have two seperate locations where you have
> > to specify how to construct the table HTML, i.e. in the kid template
> > and in the javascript (bye-bye DRY)
> >
> > I would prefer to use kid to do all my HTML generation ('cos its damn
> > good at it, and 'cos javascript isn't). I think I want to be able to
> > call a method via an AJAX request that returns the kid-generated HTML
> > (as opposed to JSON), and swap this directly into the DOM.
> >
> > I can think of a few ways of doing this:
> >
> > a) specifying a ajax parameter flag on the AJAX call, and using
> > tg_template in Root.page() to change the template to generate only be
> > the part I want (i.e. the table). This requires an additional template
> > with just the table in it, again breaking the DRY concept. You could
> > use py:def/py:match to alleviate some repetition, but I don't like the
> > idea of an extra one line file.
> >
> > b) using the AJAX request to grabbing the whole HTML document and
> > using
> > the DOM API to extract just the table part via id, and use that to
> > update the live page. This seems a little clumsy and bandwidth
> > inefficient, but requires no parameters or extra templates.
> >
> > c) have an extra method that returns just the table HTML. You could
> > use
> > this in the AJAX request, and you could also use it in the original
> > Root.page() method
> > and associated template.
> >
> > So far, I'm opting for c), but is there a better way to do it? Any
> > thoughts?
> >
> > --
> > wavy davy
> >
> >
>
> ________________________________
> Ronald Jaramillo
> mail: ronald AT checkandshare DOT com
> blog: http://www.checkandshare.com/blog
>
>
>
>