On 04.03.2008, at 10:10, Christoph Bonitz wrote:
I am trying to create several views that differ only in the value of
an integer variable in the javascript-function. I would love to do
something like
function(doc,n) {/* do something that depends on n*/}
but the view functions take only one argument. Currently I am
replicating code, i.e.
function(doc) {n = 1; /*snip*/}
function(doc) {n = 2; /*snip*/}
etc.
What exactly are you trying to do here? This sounds a bit like you
haven't discovered key/startkey/endkey filtering yet. Or that that a
single view function can return multiple rows.
Is there a way to call another javascript function from a view
function, i.e.
function(doc) {otherfunction(doc,1);}
No, you currently don't have access to any shared code outside of the
Javascript standard objects.
I think it might be nice if one could provide shared code via design
documents, but how exactly that would work (considering also the
support for different view languages/servers) would need to be fleshed
out.
or pass a parameter from the http-query? I have found nothing like
this in the wiki or on the web.
One important rule for view functions is that any data that is not
contained in the currently processed document (or that can be
deterministically derived from that document) must not be used in
views, even if it was technically possible (`new Date()` for getting
the current date/time, for example).
That is because the view function is run only on new/changed
documents, not on all docs every time the view is queried.
Cheers,
Chris
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/