[#168,docs/backend][m]: major extension to backend tutorial to give examples of most backends.

This commit is contained in:
Rufus Pollock
2012-07-08 20:52:55 +01:00
parent 4e69026881
commit 3e2fbed5c2
7 changed files with 187 additions and 10 deletions

View File

@@ -0,0 +1,22 @@
// the file input
var $file = $('.my-file-input')[0];
// listen for the file to be submitted
$($file).change(function(e) {
// create the dataset in the usual way but specifying file attribute
var dataset = new recline.Model.Dataset({
file: $file.files[0],
backend: 'csv'
});
// now load - note that this is again async (HTML5 File API is async)
// dataset.fetch().done(function() { console.log('here'); });
dataset.fetch();
// For demonstrations purposes display the data in a grid
var grid = new recline.View.Grid({
model: dataset
});
$('#my-csv-disk').append(grid.el);
});

View File

@@ -0,0 +1,17 @@
var dataset = new recline.Model.Dataset({
url: 'http://data.london.gov.uk/datafiles/transport/tfl_passengers.csv',
// optional rows parameter specifies how many rows to retrieve - default is a 1000
// rows: 5000
backend: 'dataproxy'
});
// async again as we fetch via AJAX behind the scenes
// once data is fetched it will be stored in a local MemoryStore so further querying will not involve the DataProxy
dataset.fetch();
// For demonstrations purposes display the data in a grid
var grid = new recline.View.Grid({
model: dataset
});
$('#my-dataproxy').append(grid.el);

View File

@@ -0,0 +1,13 @@
var dataset = new recline.Model.Dataset({
url: 'http://datahub.io/dataset/rendition-on-record/ac5a28ea-eb52-4b0a-a399-5dcc1becf9d9/api',
backend: 'elasticsearch'
});
dataset.fetch();
// For demonstrations purposes display the data in a grid
var grid = new recline.View.SlickGrid({
model: dataset
});
$('#my-elasticsearch').append(grid.el);

View File

@@ -15,7 +15,7 @@ $('#my-gdocs').append(grid.el);
// Now do the query to the backend to load data
dataset.fetch().done(function(dataset) {
if (console) {
console.log(dataset.currentDocuments);
console.log(dataset.records);
}
});

View File

@@ -0,0 +1,20 @@
// Create the dataset in the usual way
// Note the additional options you can specify for parsing the CSV file
var dataset = new recline.Model.Dataset({
url: '{{page.root}}/demos/data/sample.csv',
backend: 'csv',
// separator: ',',
// delimiter: '"',
// encoding: 'utf8'
});
// remember this is async so if you want to do something you need to call it in done method e.g.
// dataset.fetch.done(function(dataset) { console.log(dataset.recordCount)});
dataset.fetch();
// show the data for illustrations sake
var grid = new recline.View.Grid({
model: dataset
});
$('#my-online-csv').append(grid.el);