On Tuesday, July 3, 2012 4:27:37 PM UTC+2, Kees Bos wrote:
>
> On Tue, 2012-07-03 at 13:43 +0200, Peter Bittner wrote: 
> > Daniel, 
> > 
> > I came across the same problem when working on the console logging 
> > functionality. The trick is to squeeze everything into a variable and 
> > use the @-notation to access it from Pyjs (e.g. JS(""" 
> > eval(@{{myvar}}) """) or so). 
>
> Indeed. 
>
> > 
> > Take a look at the __debug/__info/... functions in 
> > 
> https://github.com/pyjs/pyjs/blob/master/library/pyjamas/logging/handlers.py 
> > 
> > I don't know, actually, what the @-notation does. Maybe someone more 
> > experienced here can explain? (Kees? Anthony?) 
>
> The @{{foo}} transports python variables to the javascript scope. 
>
> So, the final_setup would probably be: 
>
> def final_setup(self, selected = '"red", "green", "blue"'): 
>     myid = str(self.myid) 
>     JS('''parent.jQuery(@{{myid}}).select2({tags:[@{{selected}}]});''') 
>
>
>
I have done it like this, and it is working fine:

 class MySelect2DropDown(HTML):


    def __init__(self, values = None, width = 300, myid = None):
        if myid == None:
            myid = get_random_id()
        self.myid = myid
        html = '<select id="%s" style="width:%dpx">' % (myid, width)
        for value in values:
            html += '<option value="%s">%s</option>' % (value, values[value
])
        html += '</select>'
        HTML.__init__ (self, html)


    def final_setup(self):
        myjs = 'parent.jQuery("#%s").select2();' % (self.myid)
        Logger("MySelect2DropDown", "Now calling JS: %s" % (myjs))
        JS(""" eval(@{{myjs}}) """)


Reply via email to