0

I have some couchdb queries, for which I'm using the jquery-couchdb plugin. I'd like to compile a set of queries with which I can decide at call-time what options to set. E.g.

$db.view("design/view", {
    success: function(data) {
        // do something e.g.:
        callback_function(data);
        },
    option1: value1,
    option2: value2
    // What if I want an option3 to be set only some of the time?
});

Is there a way to achieve this? Something like running over kwargs in python, or a way to pass in an object with keys and values?

Cheers, Matt

1 Answer 1

1

Like this?

var params = {};
params.success = function(data) {
    // do something e.g.:
    callback_function(data);
    };
if (setOpt1) params.option1 = value1;
if (setOpt2) params.option2 = value2;
$db.view("design/view", params);
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, that's done it! Examples always seem to show specific queries, it looks to me that using something based on this would improve brevity!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.