-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeObject.js
45 lines (36 loc) · 1.19 KB
/
CodeObject.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
CodeObject = function() {
return {
slug: '',
toStringFunction: function(s) { return s; },
dataSlugs: [], // array of slugs for fields in order
data: [], // array of arrays of data
// The end result of transform is an object with each attribute as follows:
// fieldSlug: {
// data: {dataSlug: data[dataSlug] },
// column: { 'slug': fieldSlug, 'title': fieldTitle, 'content': transform function }
// }
transform: function() {
oAllFields = [];
for (var dataRowIndex in this.data) {
// Make data.
oThisFieldData = {};
for (var fieldIndex in this.dataSlugs) {
oThisFieldData[this.dataSlugs[fieldIndex]] = this.data[dataRowIndex][fieldIndex];
}
// Make final field object
contentFunction = function(codeSlug,fieldSlug,toStringFunction) {
return function(pRow) {
o = pRow[codeSlug][fieldSlug];
console.log("content: pRow["+codeSlug+"]["+fieldSlug+"]",o);
return o ? toStringFunction(o) : null;
}
}
oAllFields[oThisFieldData.slug] = {
data: oThisFieldData,
content: contentFunction(this.slug,oThisFieldData.slug,this.toStringFunction)
};
} // dataRowIndex
return oAllFields;
}, //transform
}
}