Skip to content

Commit 8b6992b

Browse files
committed
Get value from key first; if not existing, try recursive get
Due to splitting object field by dot (.), when an user provides a data which key has a dot, it will cause an issue for an `undefined` data which looks like not rendered. So, to solve this, we should try to get the object value from the key first. If it's not defined or null, then we will try to do the original recursive way to get value.
1 parent 2c3e39e commit 8b6992b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/react-bootstrap-table2/src/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ function splitNested(str) {
1212
}
1313

1414
function get(target, field) {
15+
const directGet = target[field];
16+
if (directGet !== undefined && directGet !== null) {
17+
return directGet;
18+
}
19+
1520
const pathArray = splitNested(field);
1621
let result;
1722
try {

packages/react-bootstrap-table2/test/utils.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ describe('Utils', () => {
1010
city: {
1111
name: 'B'
1212
}
13-
}
13+
},
14+
'person.name': 'John Doe'
1415
};
1516

1617
it('should return correct data', () => {
@@ -19,6 +20,7 @@ describe('Utils', () => {
1920
expect(_.get(data, 'address.city.name')).toEqual(data.address.city.name);
2021
expect(_.get(data, 'address.notExist')).toEqual(undefined);
2122
expect(_.get(data, 'address.not.exist')).toEqual(undefined);
23+
expect(_.get(data, 'person.name')).toEqual(data['person.name']);
2224
});
2325
});
2426

0 commit comments

Comments
 (0)