Created
December 14, 2012 04:22
-
-
Save moneal/4282681 to your computer and use it in GitHub Desktop.
Populating datasets from localstorage
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
if (Modernizr.localstorage) { | |
//console.log("Can use localstorage"); | |
var clients = localStorage.getItem("clients"); | |
// console.log(clients); | |
if ( clients == null ) { | |
// Fetch the clients list | |
$.getJSON('/api/client_list', function(data) { | |
localStorage.setItem("clients", JSON.stringify( data )); | |
populate_autocomplete( data ); | |
}); | |
} else { | |
// Use what we have | |
populate_autocomplete( JSON.parse( clients ) ); | |
} | |
} else { | |
// console.log("Can't store local :("); | |
} | |
function populate_autocomplete( clients ) { | |
// console.log( clients ) | |
$.each( clients, function( index, value ) { | |
// console.log(index + ': ' + value); | |
$('#accounts-list').append('<option value="' + value + '"/>') | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment