Skip to content

Commit a2a8cd9

Browse files
committed
Merge pull request wenzhixin#1289 from johntostring/patch-1
这样就可以支持访问JSON嵌套属性了
2 parents f825c04 + 510ef0a commit a2a8cd9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/bootstrap-table.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@
210210

211211
return dataAttr;
212212
};
213+
214+
var getItemField = function (item, field) {
215+
var props = field.split('.');
216+
var value = item;
217+
for(var p in props) {
218+
value = value[props[p]];
219+
}
220+
return value;
221+
}
213222

214223
// BOOTSTRAP TABLE CLASS DEFINITION
215224
// ======================
@@ -825,8 +834,8 @@
825834
if (that.header.sortNames[index]) {
826835
name = that.header.sortNames[index];
827836
}
828-
var aa = a[name],
829-
bb = b[name],
837+
var aa = getItemField(a, name),
838+
bb = getItemField(b, name),
830839
value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
831840

832841
if (value !== undefined) {
@@ -1416,7 +1425,7 @@
14161425

14171426
$.each(this.header.fields, function (j, field) {
14181427
var text = '',
1419-
value = item[field],
1428+
value = getItemField(item, field),
14201429
type = '',
14211430
cellStyle = {},
14221431
id_ = '',
@@ -1543,7 +1552,7 @@
15431552
index = $td[0].cellIndex,
15441553
field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
15451554
colomn = that.columns[getFieldIndex(that.columns, field)],
1546-
value = item[field];
1555+
value = getItemField(item, field);
15471556

15481557
if ($td.find('.detail-icon').length) {
15491558
return;

0 commit comments

Comments
 (0)