Skip to content

Commit b2695fd

Browse files
authored
Merge pull request #1383 from CYBAI/fix-1381
Get value from key first; if not existing, try recursive get
2 parents 2c3e39e + 8b6992b commit b2695fd

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: 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 {

Diff for: 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)