Last active
October 26, 2018 20:09
-
-
Save rbren/b962069ee7a5e79e26d04f85872393ae to your computer and use it in GitHub Desktop.
OneDB simple example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://unpkg.com/onedb-client/dist/onedb-client.min.js"></script> | |
<script> | |
var onedb = new OneDBClient({ | |
hosts: { | |
primary: {location: 'https://one-db.datafire.io'}, | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<h2>Latest status updates</h2> | |
<div id="Statuses"></div> | |
<script> | |
onedb.list('status', 'status', {sort: 'info.created:descending'}) | |
.then(function(response) { | |
var el = document.getElementById('Statuses'); | |
for (var i = 0; i < response.items.length; ++i) { | |
el.innerHTML += getHTMLForStatusUpdate(response.items[i]) | |
} | |
}) | |
function getHTMLForStatusUpdate(statusUpdate) { | |
var info = statusUpdate.$.info; | |
var html = '<h4>' + info.created_by + '</h4>'; | |
html += '<i>wrote on ' + new Date(info.created).toDateString() + '</i>'; | |
html += '<p>' + statusUpdate.status.replace(/</g,"<").replace(/>/g,">") + '</p>'; | |
return html; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment