Skip to content

Instantly share code, notes, and snippets.

Created January 5, 2013 16:38
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/4462391 to your computer and use it in GitHub Desktop.
<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)
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'
});
// Nothing is shown in template.
// Firebug shwos error "TypeError: hash is undefined: return hash._id || hash.id;" for couchdb_adapter.js:22
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment