Created
June 24, 2012 20:43
-
-
Save boxxxie/2984830 to your computer and use it in GitHub Desktop.
example of using csv show on couchdb
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
_export_csv:function(convert_to_array,file_name){ | |
var export_db = 'export_requests_rt7'; | |
var router = this; | |
var handler = { | |
success:function(resp){ | |
var href = window.location.origin + '/'+ export_db +'/_design/app/_show/csv/' + resp.id; | |
window.location.href = href; | |
}, | |
error:function(){ | |
alert('there was an error exporting your data'); | |
} | |
}; | |
if(_.isUndefined(router.current_view_data)){ | |
alert("there is no data to save"); | |
return undefined; | |
} | |
var doc = { | |
_id:$.couch.newUUID(), | |
file_name:file_name, | |
file_ext:'csv', | |
date:(new Date()).toJSON(), | |
content:convert_to_array(router.current_view_data) | |
}; | |
$.couch.db(export_db).saveDoc(doc,handler); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment