[Seaside] how to render access to a JS argument variable?

Chris Muller asqueaker at gmail.com
Fri Oct 9 21:52:40 UTC 2015


Thanks Johan, that's the kind of advice I need, as there are many ways to
do things.

Now, I am stumped (for hours!) on another very similar problem, except
instead of a single variable, I simply want to pass an argument of type
"jQuery" into jQuery's replaceWith() function, called within a onClick
handler method.  So, in my renderContentOn:, I wrote:

     | ajaxRequest |
     ajaxRequest := (html jQuery post
          url: html actionUrl;
          dataType: 'html') html: [  : replaceHtml | self invoke.
 replaceHtml render: resultWidget ].
           ....
     html script defer with:
          ((html jQuery id: buttonId) onClick:
               ((html jQuery id: replacementId) replaceWith: ajaxRequest
asJavascript) asFunction).

However, as before, the argument to replaceWith() is being rendered as a
Javascript string literal instead of the code itself.  (See red quotes,
below, I want it to stop rendering those quotes!).

    $("#id3").click(function(){$("#id4").replaceWith(*"*
$.post("/puf",["_s=C8vA8l5UNoUsGTpf","_k=B_Wk6EYdovACqAgV","2"].join("&"),"html")
*"*)})

I tried many different variations, no success.  This must be something
simple...

Thank you.

On Fri, Oct 9, 2015 at 2:25 AM, Johan Brichau <johan at inceptive.be> wrote:

> Hi Chris,
>
> I notice you figured out the use of #alias:
>
> Use the JS generation facilities only when you need to *generate* code.
> For example, to embed a server-side callback or, in general, when the code
> can only be dynamically constructed.
> In your case, I would do the following:
>
> (JSStream on: ‘console.log(event)’)
>
> Just because you can write it in Smalltalk does not mean you should :)
>
> Johan
>
> ps: your contributions are in my inbox, I will process them asap
>
> > On 09 Oct 2015, at 03:46, Chris Muller <asqueaker at gmail.com> wrote:
> >
> > Found something.  JSAlias.
> >
> >>    html span
> >>         class: 'PufMessageWidget' ;
> >>         id: (self assureHtmlIdUsing: html) ;
> >>         onClick: ((html javascript logger call: 'log' with: 'event')
> >> asFunction: #('event')).
> >
> > I gave up on onClick: since I guess its better to set up event
> > bindings through jQuery's API.  This binding does what I want, no
> > syntax error.
> >
> >     html script defer with:
> >          ((html jQuery id: (self assureHtmlIdUsing: html)) onClick:
> >               ((html javascript logger call: 'log' with: (html
> > javascript alias: 'event')) asFunction: #('event'))).
> >
> > It seems like a pretty wordy way to write console.log(event), but the
> > intent reads clearly so, that's good..
> > _______________________________________________
> > seaside mailing list
> > seaside at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20151009/dd7c77cd/attachment-0001.htm


More information about the seaside mailing list