Re: Rendering Callbacks during an Ajax callback
Johan Brichau <[email protected]>
| Newsgroups | gmane.comp.lang.smalltalk.squeak.seaside |
|---|---|
| Message-ID | <[email protected]> |
Hi Joachim, Glad to hear you are decrypting all of this. Just to add: the code I sent really only does 1 ajax request from the client to the server. The trick is that there are two callbacks attached to the same request. Of course, you can only attach a single callback that produces a response (a primary callback). But you can attach as many secondary callbacks as you want (i.e. callback:value or callback:passengers:) to a single ajax request. Have a nice weekend! Johan > On 11 Feb 2017, at 10:41, [email protected] wrote: > > Hi Johan > > > Am 11.02.17 um 10:19 schrieb Johan Brichau: >> Hey Joachim, >> >> You can use a normal seaside callback and register it to capture delegated events. >> No magic ;) >> >> html orderedList >> script: (html jQuery this >> on: ‘click’ >> selector: ‘.mylistItemClass’ >> do: ((html jQuery ajax >> callback: [:listitemId | … ] >> value: (((html javascript alias: ‘event’) access: ‘target’) access: ‘id’)) >> asFunction: #(event)) >> >> This registers the callback on the list to capture clicks on the items below it, while passing the id of the element on which the click happened to the callback. >> If you register passengers on each of the listitems, it’s more intuitive: >> >> html orderedList >> script: (html jQuery this >> on: ‘click’ >> selector: ‘.mylistItemClass’ >> do: ((html jQuery ajax >> callback: [:passenger | … ] >> passengers: ((html javascript alias: ‘event’) access: ‘target’) >> asFunction: #(event)) >> >> Obviously, this does not render anything yet. So, we need to add that functionality to the callback: >> >> | idToReRender | >> html orderedList >> script: (html jQuery this >> on: ‘click’ >> selector: ‘.mylistItemClass’ >> do: ((html jQuery ajax >> callback: [:listitemId | … idToReRender := listitemId ... ] >> value: (((html javascript alias: ‘event’) access: ‘target’) access: ‘id’)); >> script: [:s | s << ((s jQuery id: idToReRender) html: [:h | self renderMyRowWithId: idToReRender ]) ] >> asFunction: #(event)) >> > I seem to understand. This will call the server twice, once for the setting id of which item to rerender, and a second time for the actual rendering, right? My attempt tried to use the first ajax callback to do both: process the business code and answer the re-rendered row to the client, so that it just does a .replaceWith() for the row with the re-rendered one. That is why I needed to have a builder that the component could render itself onto. > > But since your aproach just registers one single callback for the whole list, it still is an improvement compared to registering the very same callback for each row - which takes a lot of time on both the server and the client. And apart from the double ajax calls, it is exactly what I want to achieve. I guess my reason for hand-written javascript here is that I like to be able to debug it and I know way too little about JQAjax' many options... time to study > > My brain is working on this, and I am really grateful for your time and help. I guess we should negotiate your reward in Maribor ;-) > > > Joachim > > > -- > ----------------------------------------------------------------------- > Objektfabrik Joachim Tuchel mailto:[email protected] <mailto:[email protected]> > Fliederweg 1 http://www.objektfabrik.de <http://www.objektfabrik.de/> > D-71640 Ludwigsburg http://joachimtuchel.wordpress.com <http://joachimtuchel.wordpress.com/> > Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1 > > _______________________________________________ > seaside mailing list > [email protected] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside _______________________________________________ seaside mailing list [email protected] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside