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).
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?)
Good luck Daniel,
Peter
2012/7/3 Daniel Gonzalez <[email protected]>:
> Hi,
>
> I am trying to define the following component, which uses native javascript:
>
> class MyTaggingComponent(HTML):
>
>
> def __init__(self, myid, values, width = 300):
> self.myid = myid
> values = ','.join(values)
> html = '<p><input type="hidden" id="%s" style="width:%dpx"
> value="%s"/></p>' % (myid, width, values)
> HTML.__init__ (self, html)
>
>
> def final_setup(self, selected = '"red", "green", "blue"'):
> my_javascript = 'parent.jQuery("#%s").select2({tags:[%s]});' %
> (self.myid, self.selected)
> JS(my_javascript)
>
> I get a compile error: "JS function only supports constant strings".
>
> This is a big problem, since, in order to reuse this component, I need to
> have variable content in the inline javascript. I have taken a look at the
> implementation of JS in pyjs/pyjs/src/pyjs/translator_proto.py, but it is
> not clear for me whether bypassing this restriction is possible, or how
> could it be done.
>
> Could you suggest a workaround?
>
> Thanks,
> Daniel