How to reference nesting database items in couchapp

I am learning couchapp and it looks pretty easy for querying database items.

But I have elements with attachments, and I would like to add hyperlinks to the attachments:

<a href="/databasename/{{id}}/{{attachment}}">{{description}}</a> 

I can configure id , attachment and description correctly, but how to get the current database name (or URL) from the javascript function in couchapp?

+4
source share
1 answer

If you do not want to use relative URLs, you can get the db name as follows:

 var dbname = unescape(document.location.href).split('/')[2] 

as your href looks like this: http://host:port/dbname/doc...

This is also used by jquery.couch.app.js code. Therefore, if you use it, it is available to you in the initialization code:

 $.couch.app(function(app) { alert(app.db.name); }); 
+3
source

Source: https://habr.com/ru/post/1381759/


All Articles