Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 2740b73

Browse files
committed
fixes nezroy#1
1 parent a376c86 commit 2740b73

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

src/SDD.Table.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ME.D = {
1717
'keyname': null, // the primary key name
1818
'columns': [], // the list of columns
1919
'colmap': {}, // a reverse lookup map for column indexes
20+
'colmeta': {}, // a map of metainfo about each complex column
2021
'subkeys': [], // any subkeys (this implies a nested entry structure)
2122
'data': {}, // the data for this table (shallow references into raw data from source)
2223
'segments': [], // the segment information for this table
@@ -52,16 +53,28 @@ ME.Create = function (name, src, meta) {
5253
if (meta.hasOwnProperty('k')) {
5354
keyarr = meta['k'].split(':');
5455
obj.keyname = keyarr.shift();
55-
obj.subkeys.push(keyarr);
56+
for (i = 0; i < keyarr.length; i++) obj.subkeys.push(keyarr[i]);
5657
}
5758

58-
// if this table has a column array, create a reverse lookup map for it
59-
if (meta.hasOwnProperty('c') && meta['c'].length > 0) {
60-
E.extend(true, obj.columns, meta['c']);
61-
if (obj.keyname) obj.columns.unshift(obj.keyname);
62-
else obj.columns.unshift('index');
63-
for (i = 0; i < obj.columns.length; i++) obj.colmap[obj.columns[i]] = i;
64-
obj.colmap['index'] = 0;
59+
// add keys to the column definition
60+
if (obj.keyname) obj.columns.push(obj.keyname);
61+
else obj.columns.push('index');
62+
for (i = 0; i < obj.subkeys.length; i++) {
63+
obj.columns.push(obj.subkeys[i]);
64+
}
65+
66+
// add meta columns to column definition
67+
if (meta.hasOwnProperty('c')) {
68+
for (i = 0; i < meta['c'].length; i++) obj.columns.push(meta['c'][i]);
69+
}
70+
71+
// create a reverse lookup map for columns
72+
for (i = 0; i < obj.columns.length; i++) obj.colmap[obj.columns[i]] = i;
73+
obj.colmap['index'] = 0;
74+
75+
// grab the colmeta extra info
76+
if (meta.hasOwnProperty('m')) {
77+
E.extend(true, obj.colmeta, meta['m']);
6578
}
6679

6780
// grab the length
@@ -114,6 +127,21 @@ P.GetValue = function (key, col) {
114127
return entry[col];
115128
};
116129

130+
_P.UnshiftIndexes = function(data, indexes) {
131+
var key, i;
132+
for (key in data) {
133+
if (!data.hasOwnProperty(key)) return;
134+
if (!data[key]) return;
135+
indexes.push(key);
136+
if (data[key] instanceof Array) {
137+
for (i = indexes.length - 1; i >= 0; i--) {
138+
data[key].unshift(indexes[i]);
139+
}
140+
indexes.pop();
141+
}
142+
else _P.UnshiftIndexes(data[key], indexes);
143+
}
144+
};
117145
_P.SegLoadDone = function(tag, data, done, p, ctx) {
118146
var i, key;
119147
done.has++;
@@ -122,9 +150,10 @@ _P.SegLoadDone = function(tag, data, done, p, ctx) {
122150
if (data['tables'].hasOwnProperty(this.name) && data['tables'][this.name].hasOwnProperty('d')) {
123151
if (!data['tables'][this.name].hasOwnProperty('U')) {
124152
// put the index value into the first column of every row
125-
for (key in data['tables'][this.name]['d']) {
153+
_P.UnshiftIndexes(data['tables'][this.name]['d'], []);
154+
/* for (key in data['tables'][this.name]['d']) {
126155
data['tables'][this.name]['d'][key].unshift(key);
127-
}
156+
} */
128157
data['tables'][this.name]['U'] = true;
129158
}
130159
E.extend(this.data, data['tables'][this.name]['d']);

0 commit comments

Comments
 (0)