Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 72194 invoked from network); 6 Apr 2008 03:22:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Apr 2008 03:22:35 -0000 Received: (qmail 87129 invoked by uid 500); 6 Apr 2008 03:22:35 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 87094 invoked by uid 500); 6 Apr 2008 03:22:35 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 87085 invoked by uid 99); 6 Apr 2008 03:22:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Apr 2008 20:22:35 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jchris@gmail.com designates 72.14.220.153 as permitted sender) Received: from [72.14.220.153] (HELO fg-out-1718.google.com) (72.14.220.153) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Apr 2008 03:21:51 +0000 Received: by fg-out-1718.google.com with SMTP id 22so836490fge.26 for ; Sat, 05 Apr 2008 20:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=JcyA7hsPJWqL+1w+Ygr+4aqseyl2M9YQu3XaIJNgDsA=; b=xXJneRNlzpQ/2MSSfkWTf68RZKy76UFtqXvxYtFBncB6+FjY72GxMOmyD8e+vfXbihM3B3BIm26EAGPm9E0n19JB94uEDMOf2j1NQFVHmGzGc/M7TKPrv/dxvxTIq5i76w/XReKQKvNApFUGSNuMahqhL3yb7W9HY+EtLYyRN9w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=GepXAEB9A+OsJmPr5fGk0CpGg0bpglLbN2gal+5ypfknKG5jfk8CplWe4iTsHdOyW95UUd64f+TjpDdz6qSnYRgVt78Ohp244Rpf0ept+xt/H45lap2gWUfMOcZfzsF227egfHk8gcNDS5OVmDYvjfd0pl/ETNlGUArSJjt5t7E= Received: by 10.86.57.9 with SMTP id f9mr2221356fga.28.1207452122900; Sat, 05 Apr 2008 20:22:02 -0700 (PDT) Received: by 10.86.57.13 with HTTP; Sat, 5 Apr 2008 20:22:02 -0700 (PDT) Message-ID: Date: Sat, 5 Apr 2008 20:22:02 -0700 From: "Chris Anderson" Sender: jchris@gmail.com To: couchdb-user@incubator.apache.org Subject: Re: Javascript views don't support for loops? In-Reply-To: <29A12A47-BE5E-49BA-9DF3-EC750DF9AB34@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <958d06600803021810n23d3c860w1d4b3f1f75eb2715@mail.gmail.com> <29A12A47-BE5E-49BA-9DF3-EC750DF9AB34@gmail.com> X-Google-Sender-Auth: 2efaaf25537ae23c X-Virus-Checked: Checked by ClamAV on apache.org Sebastian, I had a similar problem, and found the solution in declaring the var in my for loop. Like this: function(doc){ if (doc.class == "Entry"){ for (var n in doc.scores){ map(doc.user, doc.scores[n]); } } } Oh but that was with an Object. Going on to read that you are using an array, you could try a loop like this: function(doc){ if (doc.class == "Entry"){ for (var i=0, s; s = doc.scores[i]; i++) { map(doc.user, s); } } } Although that second one is just copied from my client side code, so it might not be the most efficient way to iterate in Spidermonkey. hope this helps, Chris On Sat, Apr 5, 2008 at 8:07 PM, Guby wrote: > Hi > I am trying to write a view where I want a for loop to loop through one of > the parameters in the document and then create several entries for the > document based on the parameters content. > > The view would look something like this: > > function(doc){ > if (doc.class == "Entry"){ > for (n in doc.scores){ > map(doc.user, doc.scores[n]); > } > } > } > > where doc.scores is an array. > > When I am inserting a for (x in y) or for (n = 0; n<10, n=n+1) or anything > of the kind the view just doesn't execute at all! > Is this a known limitation? > I have to create several entries for each document based on this array! > Is there a good workaround you guys could suggest? > > Best regards > Sebastian > -- Chris Anderson http://jchris.mfdz.com