Friday 23 November 2018

You probably know what's wrong with this code

New to web dev, I'm trying to 'insert' into couchdb an array of tag's. I think I'm probably just not seeing the right 'angle' to tackle this problem. I'm trying to do a function in the app.js post function that takes in the string from the box and replaces the 'tag' section with what I want, but I'm not sure how to return it properly given I can't return it as a full string (i.e. "tag1, tag2, tag3") it has to be strings seperated by commas ("tag1","tag2","tag3"). Can you just point me in the right direction? maybe I should be doing this in the webpage js instead, or is there a cleaner way?​ //working, passing just the value couch.insert('master_db', { //accepts the following properly //tags: ["tag1","tag2","tag3","tag4"] //just takes in the whole thing like a string value (1 tag) tags:[tags]; }) /*couch.insert('master_db', { tags:[(function(tags){ console.log("got here"); console.log(tags); var array = []; var string =""; for (var i = 0; i < tags.length; i++) { if (tags.charAt(i)==","){ array.push(string); string=""; } else{ string=string+tags.charAt(i); } } return array; })] })*/ ​

Submitted November 23, 2018 at 02:23PM by Auklin

No comments:

Post a Comment