Created
March 15, 2013 17:18
-
-
Save andrewxhill/5171504 to your computer and use it in GitHub Desktop.
Using Bootstrap Typeahead based on a CartoDB column
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Typeahead + CartoDB</title> | |
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<div class="well"> | |
<input type="text" class="span3" id="filter" data-provide="typeahead" data-items="4" /> | |
</div> | |
<script src="http://libs.cartocdn.com/cartodb.js/v2/cartodb.js"></script> | |
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js"></script> | |
<script> | |
var sql = new cartodb.SQL({ user: 'viz2', format: 'json'}); | |
sql.execute("SELECT distinct name FROM d3_world_borders ORDER BY name").done(function(data){ | |
var subjects = []; | |
for (var i = 0; i < data.rows.length; i++){ | |
subjects.push(data.rows[i].name) | |
}; | |
$('#filter').typeahead({source: subjects}) | |
}) | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment