public
Last active — forked from /Minimal couchdb_example

  • Download Gist
Minimal couchdb_example.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
<html>
<head>
<title>ToDo List</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style></style>
<title>CouchDB jQuery Examples</title>
<script src="script/jquery.js"></script>
<script src="script/handlebars.js"></script>
<script src="script/ember.js"></script>
<script src="script/ember-data.js"></script>
<script src="script/couchdb_adapter.js"></script>
 
<script type="text/javascript">
App = Ember.Application.create();
 
App.store = DS.Store.create({
adapter: DS.CouchDBAdapter.create({
db: 'testdb',
designDoc: 'todo'
}),
revision: 11
});
ToDo = DS.Model.extend({
type: DS.attr('string'),
title: DS.attr('string'),
content: DS.attr('string'),
creator: DS.attr('string'),
created_at: DS.attr('string'),
done: DS.attr('string'),
}),
App.todo = App.store.find(ToDo, '72674863c864a2dde83ffa535a007e4c')
// Document is found and title is shown in tenplate (App.todo.title)
App.todo = App.store.createRecord(ToDo, {
type: 'ToDo',
title: 'New ToDo',
content: 'Some Details',
creator: 'Me',
created_at: '2013-01-05',
done: 'false'
});
App.store.commit();
// Document is stored as expected
 
App.todos = App.store.findQuery(ToDo, {
type: 'view',
viewName: 'todos',
options: {
include_docs: true
}
});
 
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
 
</script>
 
</head>
 
<body>
<script type="text/x-handlebars" data-template-name="application">
<h1>Data</h1>
{{App.todo.title}}
{{#each App.todos}}
{{title}}
{{/each}}
</script>
 
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.