Alright, I think I've got it. General.GetJSONArrayFromTableHandout = function (handoutName, afterCallback, callbackArray) {
var handout = findObjs({ type: 'handout', name: handoutName })[0];
if (handout) {
handout.get('notes', function (notes) {
callbackArray.push(General.TableToJSONArray(notes, handoutName));
afterCallback();
});
}
}
General.TableToJSONArray = function(html, title) {
var table = html;
table = table.replace('<table>', '').replace('</table>', '').replace('<thead>', '').replace('</thead>', '').replace('<tbody>', '').replace('</tbody>', '');
var headers = [];
var items = table.split('</tr>');
var output = { data: [], Name: title };
var headerRow = 1;
_.each(items, function (item) {
if (item != '') {
var index = 0;
item = item.replace('<tr>', '');
var jsonString = '{ ';
var values = item.split('</td><td>');
_.each(values, function (value) {
value = value.replace('<td>', '');
value = value.replace('</td>', '');
if (headerRow == 1) {
headers.push(value.replace( new RegExp(' ','g'),'_'));
} else {
if (index > 0) {
jsonString = jsonString + ', ';
}
jsonString = jsonString + '"' + headers[index] + '" : "' + value + '"';
}
index = index + 1;
});
jsonString = jsonString + ' }';
if (headerRow != 1) {
output.data.push(JSON.parse(jsonString));
}
}
headerRow = 0;
});
return output;
};
characterSheet.CalculateAbilityDerivedValues = function (characterId) {
var abilityTables = [];
var callback = _.after(8, function () {
/* Do work here */
});
General.GetJSONArrayFromTableHandout('Intelligence', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Wisdom', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Charisma', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Strength', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Dexterity', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Constitution', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Comeliness', callback, abilityTables);
General.GetJSONArrayFromTableHandout('Speed', callback, abilityTables);
}
My implementation here might be a little dirty, but I'm spoiled by the .NET library at work, so parsing HTML tables into JSON isn't really my strong suit.