Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27154
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: javascript loop problem |
| Date | Wed, 01 Apr 2015 14:42:43 +0200 |
| Organization | solani.org |
| Lines | 32 |
| Message-ID | <mfgp3r$ir$1@solani.org> (permalink) |
| References | <8f8b8bbd-fed1-4871-b3e4-e0b96abd3692@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | solani.org 1427892155 603 eJwNysERwDAIA7CVcMBA1ql73n+EVm8xG62pZhdNI44KQCk991rxh9lepu18VAlEMUZ49+wH/JIP2g== (1 Apr 2015 12:42:35 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Wed, 1 Apr 2015 12:42:35 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
| X-User-ID | eJwNyskBACAIA7CVRKTUcZRj/xE075hCEL5gWNbWk+PkDjgjq0UJzRPUhgNSwyuJkl1X4v74ACJtEag= |
| In-Reply-To | <8f8b8bbd-fed1-4871-b3e4-e0b96abd3692@googlegroups.com> |
| Cancel-Lock | sha1:/YfcKnTSTFC2sJqq0loTEnwe9FU= |
| X-NNTP-Posting-Host | eJwNykkBwDAIBEBLLHfkQCj+JaTzHhOH31A3V1vbU4O6Y9zJ04fE99PUXSQQtIPggVT/b0jpASgfEUc= |
| Xref | csiph.com comp.lang.javascript:27154 |
Show key headers only | View raw
chrisb@ctlsoft.com wrote:
> little script which adds map markers to the appropriate locations with a label.
> The array 'myaddresses' contain the locations to mark on the map and the numbers to put on the labels.
> Works fine for the location bit, but the labels all show the last count (35).
>
> So the line labelContent: myaddresses[x][1] always seems to return the final array element for some reason.
When this expression is evaluated, x === myaddresses.length-1.
> <script type='text/javascript'>
> $(window).load(function(){
> $(document).ready(function () {
That seems clumsy at best. You'll want to skip registering an event
listener for window's load event, here.
> var myOptions = {
> zoom: 6,
> center: new google.maps.LatLng(-42.397, 172.644),
> mapTypeId: 'terrain'
> };
> var map = new google.maps.Map($('#map_canvas')[0], myOptions);
>
> var myaddresses = [['Cambridge', 100], ['Auckland',20], ['Wellington',1], ['Taupo',35]];
>
> for (var x = 0; x < myaddresses.length-1; x++) {
Don't use a for loop here, but rather $.each().
--
Christoph M. Becker
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
javascript loop problem chrisb@ctlsoft.com - 2015-03-31 19:05 -0700 Re: javascript loop problem Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2015-04-01 10:49 +0800 Re: javascript loop problem "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-01 14:42 +0200 Re: javascript loop problem Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-01 14:43 +0000
csiph-web