Last active
December 5, 2017 07:07
-
-
Save cryocaustik/f2704fe256cdfe83532f3363572daeb0 to your computer and use it in GitHub Desktop.
simple ajax to pull csv and return a predefined dictionary
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
function dataImport() { | |
var pathData = 'https://gist.githubusercontent.com/cryocaustik/cc33ed8db15683160bf64d4981f7c3f2/raw/1fa0c63dd79a4b3e976798ca48a098147d27917f/csv_test'; | |
var jsonData; | |
$.ajax({ | |
url: pathData, | |
async: false, | |
success: function(data) { | |
_data = data.split('\n').slice(1); | |
for (var row_indx in _data) { | |
_row = _data[row_indx].split(','); | |
if ($.isEmptyObject(jsonData)) { | |
jsonData = { | |
'name': _row[0], | |
'title': 'head', | |
'children': [{ | |
'name': _row[1], | |
'title': _row[2], | |
'className': _row[3] | |
}] | |
}; | |
} else { | |
jsonData.children.push({ | |
'name': _row[1], | |
'title': _row[2], | |
'className': _row[3] | |
}); | |
} | |
} | |
} | |
}); | |
return jsonData; | |
} | |
console.log('results', JSON.stringify(dataImport())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment