* RowsToFields: Fix issue with field names that are numbers
* Only add the index accessor if field name does not conflict with it
* fix lint
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
(cherry picked from commit 25813db334)
Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
co-authored by
Torkel Ödegaard
parent
363a94ff21
commit
41a9638df7
@@ -81,4 +81,19 @@ describe('dataFrameView', () => {
|
||||
value: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('Can handle fields with number name', () => {
|
||||
const view = new DataFrameView<MySpecialObject>(
|
||||
new MutableDataFrame({
|
||||
fields: [
|
||||
{ name: '1', type: FieldType.string, values: ['a'] },
|
||||
{ name: '2', type: FieldType.string, values: ['b'] },
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
const obj = view.get(0) as any;
|
||||
expect(obj['1']).toEqual('a');
|
||||
expect(obj['2']).toEqual('b');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,10 +32,12 @@ export class DataFrameView<T = any> extends FunctionalVector<T> {
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(obj, i, {
|
||||
enumerable: false, // Don't enumerate array index
|
||||
get: getter,
|
||||
});
|
||||
if (!(obj as any).hasOwnProperty(i.toString())) {
|
||||
Object.defineProperty(obj, i, {
|
||||
enumerable: false, // Don't enumerate array index
|
||||
get: getter,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.obj = obj;
|
||||
|
||||
Reference in New Issue
Block a user