Created
January 11, 2017 07:03
-
-
Save edwardwbli/40a6354c1b5a5fd0fc8b850ae5a2f2be to your computer and use it in GitHub Desktop.
example for Jquery to use Gundb
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> | |
<body> | |
<h1>Thoughts</h1> | |
<form> | |
<input><button>Add</button> | |
</form> | |
<ul></ul> | |
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> | |
<script src="https://rawgit.com/amark/gun/e9e8804de8249f58340e3810721cd5c2a0f78fcd/gun.js"></script> | |
<script> | |
var gun = Gun().get('thoughts'); | |
$('form').on('submit', function(event){ | |
event.preventDefault(); | |
gun.set($('input').val()); | |
$('input').val(""); | |
}); | |
gun.on().map(function(thought, id){ | |
var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul'); | |
if(thought){ | |
$(li).text(thought); | |
} else { | |
$(li).hide(); | |
} | |
}); | |
$('body').on('dblclick', 'li', function(event){ | |
gun.path(this.id).put(null); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment