Skip to content

Instantly share code, notes, and snippets.

@mzikherman
Created February 1, 2013 00:35
Show Gist options
  • Save mzikherman/4688105 to your computer and use it in GitHub Desktop.
Save mzikherman/4688105 to your computer and use it in GitHub Desktop.
Attempt at making a generic config for any collection
generateStandardCSVConfiguration: ->
retConfig = []
for fldName, fldValue of @models[0].attributes
retConfig.push [ fldName, (o) -> o.get("#{fldName}") ]
retConfig
@mzikherman
Copy link
Author

Hey Craig- quick question, any idea why the above is acting weird? I was thinking we could put a method like this on a collection, so getting that collection to CSV would be like:

new App.Lib.CSV( @models, @generateStandardCSVConfiguration )

My intention was to basically loop over all the attributes on the model and do this mapping for the CSV library. The issue is the (o) -> o.get("#{fldName}") seems to not be doing the string evaluation, so the config winds up looking like:

function (o) { return o.get("" + fldName); }

whereas I wanted that string to be evaluated, so it should be:

function (o) { return o.get("name"); }
function (o) { return o.get("years"); }

and so on. Am I doing something bizarre?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment