Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习 couchapp,它看起来很容易查询数据库项目。
但是我有带有附件的项目,我想在附件中添加超链接:
<a href="/databasename/{{id}}/{{attachment}}">{{description}}</a>
我可以正确获取id和设置attachment,description但是如何从 couchapp javascript 函数中获取当前数据库名称(或 URL)?
id
attachment
description
如果您不想使用相对 url,可以通过以下方式获取数据库名称:
var dbname = unescape(document.location.href).split('/')[2]
因为你的 href 看起来像:http://host:port/dbname/doc...
http://host:port/dbname/doc...
这也是 jquery.couch.app.js 使用的代码。因此,如果您正在使用它,它可以在初始化代码中为您提供:
$.couch.app(function(app) { alert(app.db.name); });