0

I'm trying to read the return value from a CouchDB _update, which returns a string. I'm calling it via an AngularJS $resource, like so:

var cb = function(rtn){console.log(rtn);};
var foo = $resource('/myDb/_design/myDesignDoc/_update/thingie/:arg', {}, { update: {method: 'PUT'}});
foo.update({arg: "blah"}, null, cb);

This prints the following to the console:

Object { 0: "4", 1: "d", 2: "a", 3: "7", 4: "3", 5: "1", 6: "1", 7: "4", 8: "-", 9: "8", 51 more… }

The attributes with the numeric indexes are my desired output, but how to convert them back into a string?

I've tried rtn.join("") but it complains about not finding rtn.join. I suspect this of being obvious, but I'm stuck for now...

1 Answer 1

0

This (unanswered) question appears to be very similar to mine. This one was self-answered, suggesting returning a dictionary rather than a string. Simply returning a dictionary didn't work for me, but returning a JSON string containing a dictionary did, like so:

JSON.stringify({rtn_value: "the actual return value"})

Grumble. This should really be added to the AngularJS docs... maybe I'll do it (or better, someone who reads this should do so!)

Sign up to request clarification or add additional context in comments.

Comments

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.