5 Replies Latest reply on Mar 11, 2011 8:42 AM by v.bannur

    How to get data attributes in JS

    v.bannur

      Hi

      I looked the source code for the Gmap it was a list.

       

      One more point I want to understand is:

       

      <a4j:jsFunction name="loadPoints" data="#{gmBean.point}" oncomplete="createPoints(data)" />

       

      function createPoints(data) {

        alert(data.length);

        for (var i = 0; data.length; i++) {

      alert(data.lat);

        var point = new GLatLng(data.lat, data.lng);

        map.addOverlay(createMarkerWithIdentifier(point, data.desc));

        }

        }

       

       

       

       

       

      Is  "data=#{gmBean.poin}" in a4j:jsFunction being passed to javascript in oncomplete ... as data?

       

      in other words, is list passed to javascript by data variable as shown in above code ?

       

      If yes then I am getting undefined value on alert(data.lat); Even i tried data.getAttribute("lat") is not working.

      How to get data attributes in JS?

       

      Please please help me.

        • 1. How to get data attributes in JS
          ilya_shaikovsky

          use event.data

          • 2. How to get data attributes in JS
            v.bannur

            Hi Ilya,

             

            I have used event.data as below

             

            <a4j:jsFunction name="loadPoints" data="#{gmBean.point}" oncomplete="createPoints(event.data)" />

             

            function createPoints(data) {

                                           alert(data.length);

                                           for (var i = 0; data.length; i++) {

                                                     alert(data.lat);

                                                     var point = new GLatLng(data.lat, data.lng);

                                                     map.addOverlay(createMarkerWithIdentifier(point, data.desc));

                                                     }

                                           }

             

            Before i was geting size of the data list as value 4. Now that also i am not getting.

            • 3. Re: How to get data attributes in JS
              v.bannur

              Hi Ilya,

               

              Can you please help me in this. I stucked here.

              Even though  'event.data' i am not getting attribute value.

               

              I have attached the files.

              • 4. Re: How to get data attributes in JS
                ilya_shaikovsky

                Doh.. sorry. my mistake with event.data.. that's from 4.x

                 

                you was right using oncomplete="createPoints(data)"

                 

                need just one correction:

                function createPoints(data) {

                                               alert(data.length);

                                               for (var i = 0; data.length; i++) {

                                                         var point = new GLatLng(data[i].lat, data[i].lng);

                                                         map.addOverlay(createMarkerWithIdentifier(point, data[i].desc));

                                                         }

                                               }

                note the data[i] usage as you passing the array to the handler.

                Checked that it works for me fine.

                • 5. Re: How to get data attributes in JS
                  v.bannur

                  Thank youuuuuuuuu very much.