Skip to content

Instantly share code, notes, and snippets.

@martinthenext
Created December 15, 2011 19:18
Show Gist options
  • Save martinthenext/1482413 to your computer and use it in GitHub Desktop.
Save martinthenext/1482413 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<style>
p { color:red; margin:5px; cursor:pointer; }
p.hilite { background:yellow; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="/_utils/script/sha1.js"></script>
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js"></script>
<script src="/_utils/script/jquery.couch.js"></script>
<script src="vendor/couchapp/jquery.couchLogin.js"></script>
<script src="vendor/couchapp/jquery.couchProfile.js"></script>
<script src="vendor/couchapp/md5.js"></script>
<script src="vendor/couchapp/jquery.mustache.js"></script>
</head>
<body>
<h2>We're now in <span id="current_db">no</span> database</h2>
<div id="db_list">
<ul id="db_list_content"></ul>
</div>
<h2>Documents</h2>
<div id="doc_list">
<ul id="doc_list_content"></ul>
</div>
</ul>
<h2>Document <span id="current_doc"></span></h2>
<div id='doc'>
<table id='doc_table'></table>
</div>
<script>
$('document').ready(function () {
$.couch.allDbs({
success : function(data) {
$.each(data, function(index, value) {
$('#db_list_content').append('<li class="db_name">' + value + '</li>');
});
<!-- Только когда приходят данные, мы вешаем событие -->
$('.db_name').click(function() {
$('#doc_table').html('');
$('#current_db').html($(this).html());
var db = $.couch.db($(this).html());
db.allDocs({
success : function(data) {
$('#doc_list_content').html('');
console.log(data);
$.each(data.rows, function(index, value) {
$('#doc_list_content').append('<li class="doc_name">' + value.key + '</li>');
});
<!-- Данные пришли, можем вешать событие -->
$('.doc_name').click(function() {
var doc_id = $(this).html().toString()
console.log(doc_id);
db.openDoc(doc_id, {
success : function(data) {
$('#doc_table').html('');
$('#current_doc').html(doc_id);
$.each(data, function(index, value) {
$('#doc_table').append('<tr><td>' + index + '</td><td>' + value + '</td></tr>');
});
}
});
});
}
});
});
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment