calling javascript function from amber

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

calling javascript function from amber

laci
Q1. How do I call a javascript function like the one below from amber?

function show() {
  $('.table > thead > tr > th[name]').each(
    function(idx,elt) {
     console.log(idx + ':' + elt);
     console.log(elt);
     console.log($(elt).attr('name'));
  });
}

Q2. How do I implement this code in amber/smalltalk?
  $('.table > thead > tr > th[name]').each(
    function(idx,elt) {
     console.log($(elt).attr('name'));
  });

'.table > thead > tr > th[name]' asJQuery class ==> JSObjectProxy
which is actually a collection of jQuery objects. Ho do I navigate this collection in amber?

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: calling javascript function from amber

Esteban A. Maringolo
To call the global show() function, send the message show to the global object (window).
It is: window show.

Using the same object (JSObjectProxy) when you get a JQuery object as a result, you can invocate its methods the same way, using Smalltalk blocks instead of JS functions.

It is:
(window jQuery: '.table > thead > tr > th[name]') each: [:idx :elt |
  console log: (elt attr: 'name').
]

Check: http://amber-lang.net/documentation.html#JSObjectProxy



Reply | Threaded
Open this post in threaded view
|

Re: calling javascript function from amber

laci
Thanks Esteban.