Thanks istvan, this is working!

On Wednesday, July 11, 2012 9:37:24 PM UTC+2, istvan.vago wrote:
>
>  Daniel,
> try this:
>
>       def bind_pyjs_change(self):
>         # This is supposed to bind the change event to the change pyjs 
> function
>         # Since we are binding a global function to the self.change 
> method, we want
>         #   that global function to be unique (or at least to have the 
> myid suffix)
>         global_unique_change = "change_%s" % (self.myid)
>         setattr(wnd(),global_unique_change,self.change)
>         # Now bind the change event to the wnd().global_unique_change 
> function, which is actually self.change
>         myjs = 'parent.jQuery("#%s").bind("change", function() { 
> parent.%s() });' % (self.myid, global_unique_change)
>         log.info("Now calling JS: %s", myjs)
>         JS(""" eval(@{{myjs}}) """)
>  
> Regards,
> Istvan
>
>  
> 2012-07-11 17:22 keltezéssel, Daniel Gonzalez írta:
>  
> Thanks for your help, this is now working. I have an example more or less 
> complete here: 
>
>  git clone g...@github.com:gonvaled/pyjs.git
>  cd pyjs/examples
> python jquery-select2 --download
>  
>  There is still one important issue open: the self.change method is bound 
> to wnd().change. See here:
>
> https://github.com/gonvaled/pyjs/blob/master/examples/jquery-select2/Select2TaggingComponent.py#L57
>  
>  If there are multiple Select2TaggingComponent defined, they will 
> overwrite this binding, so that only the last one is really active.
> You can see the problem in the example application, which has two 
> components defined.
>
>  The solution would be to do somehting like this:
>
>       def bind_pyjs_change(self):
>         # This is supposed to bind the change event to the change pyjs 
> function
>         # Since we are binding a global function to the self.change 
> method, we want
>         #   that global function to be unique (or at least to have the 
> myid suffix)
>         global_unique_change = "change_%s" % (self.myid)
>         wnd().global_unique_change = self.change
>         # Now bind the change event to the wnd().global_unique_change 
> function, which is actually self.change
>         myjs = 'parent.jQuery("#%s").bind("change", function() { 
> parent.%s() });' % (self.myid, global_unique_change)
>         log.info("Now calling JS: %s", myjs)
>         JS(""" eval(@{{myjs}}) """)
>  
>  The problem is that wnd().global_unique_change = self.change generates:
>
>  $wnd['__is_instance__'] && typeof $wnd['__setattr__'] == 'function' ?$wnd
> ['__setattr__']('global_unique_change', $p['getattr'](self, 'change')) :$p
> ['setattr']($wnd, 'global_unique_change', $p['getattr'](self, 'change'));
>  
>  As you see, 'global_unique_change' is taken as literal, but should be a 
> variable in this particular case. It should generate:
>
>   $wnd['__is_instance__'] && typeof $wnd['__setattr__'] == 'function' ?$wnd
> ['__setattr__'](global_unique_change, $p['getattr'](self, 'change')) : $p[
> 'setattr']($wnd, global_unique_change, $p['getattr'](self, 'change'));
>  
>  I have modified that manually in the output javascript, and it works. 
> Now the question is how to tell pyjscompile to do the "right thing". I 
> realize this is very special case, but how can it be covered?
>
>  Thanks,
> Daniel
>
>  
>  
>
> 

Reply via email to