質問

In raw jQuery you can use

var $th = $td.closest('table').find('th').eq($td.index());

But, how do I return $th to seaside so I can then use it as a string for whatever rending I want? Example.

val do:[:e |
e class = Dictionary ifTrue:[
                        html tableData 
                        onDoubleClick: (html javascript alert: 'double clicked column'); 
                        with:[self renderTargets: e on: html]
                           ]
         ]

So basically I want the value of:

(((html jQuery this) next: 'td') closest: 'table'; find: 'th'; eq: ((html jQuery this) next: 'td') index; html).

and put it at the end of

...column', thValue);

I don't know javascript, jquery or ajax all that well, outside of seaside.

WWLD? Thanks

役に立ちましたか?

解決

To pass a value from the webpage back to the server, you can make an ajax callback using jQuery. Something along the lines of:

html tableData 
      onDoubleClick: (html jQuery ajax 
                            callback: [:v | .. do something with v... ]
                            value: ((((html jQuery this)) closest: 'table') find: 'th' ...)

The first argument (i.e. the callback block) of the #callback:value: message will be evaluated server-side with the value of the client-side evaluation of its second argument (i.e. a javascript expression).

Take a look at the JQAjax hierarchy. You will notice many variants to the #callback:value: method (e.g. with json, passengers, etc...).

In addition, you can combine the #callback:value: callback with a response-rendering ajax callback such as #script: to execute a script client-side. You can even pass values between the different callback blocks:

html jQuery ajax
      callback: [:v | theValue := v]
      value: ((((html jQuery this)) closest: 'table') find: 'th' ...);
      script: [:s | s << (s alert: theValue)]

The code above will get the value from the jQuery expression, serialize it to the server, store it in the variable theValue and then render a javascript response that produces an alert dialog displaying that value. This is obviously just to demonstrate what is possible. In this example the callback to the server is rather useless. If you do not need the value server-side, then use plain Javascript on the client.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top