开发者

Getting the value of a JQueryInstance

开发者 https://www.devze.com 2023-02-11 05:18 出处:网络
I\'m still trying to get to understand how Javascript is wrapped in Seaside, say I have the following query:

I'm still trying to get to understand how Javascript is wrapped in Seaside, say I have the following query:

(html jQuery: '#myId') hasClass: 'myClass'

How do I get a true or a false out of this? For example in my case I'd love to be able to do:

html anchor
   onClick: 
      (((html jQuery: '#myId') 
          hasClass: 'myClass') 
              ifTrue: [doSomething开发者_如何学Go]
              ifFalse: [doSomethingElse]);
   with: 'Magic Stuff!'

What's the seaside way of doing this?

Thanks!


Depends where you want to perform the decision on the client or on the server?

Decide and Perform Action on Client

You can use

((html jQuery: '#myId') hasClass: 'myClass') 
   then: aTrueExpression
   else: aFalseExpression

where aTrueExpression' andaFalseExpression' are other (jQuery) JavaScript expressions.

Decide and Perform Action on Server

You serialize the result of your expression into an AJAX callback and perform the action on the Smalltalk side:

html jQuery ajax
   callback: [ :value |
       value = 'true'
           ifTrue: [ " true block " ]
           ifFalse: [ " false block " ] ]
   value: ((html jQuery: '#myId') hasClass: 'myClass')
0

精彩评论

暂无评论...
验证码 换一张
取 消