Skip to content

Commit 510ef0a

Browse files
committed
排序支持访问嵌套属性
1 parent d654c8f commit 510ef0a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/bootstrap-table.js

Lines changed: 11 additions & 11 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
// ======================
@@ -814,8 +823,8 @@
814823
if (that.header.sortNames[index]) {
815824
name = that.header.sortNames[index];
816825
}
817-
var aa = a[name],
818-
bb = b[name],
826+
var aa = getItemField(a, name),
827+
bb = getItemField(b, name),
819828
value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
820829

821830
if (value !== undefined) {
@@ -1335,15 +1344,6 @@
13351344
var that = this,
13361345
html = [],
13371346
data = this.getData();
1338-
1339-
function getItemField(item, field) {
1340-
var props = field.split('.');
1341-
var value = item;
1342-
for(var p in props) {
1343-
value = value[props[p]];
1344-
}
1345-
return value;
1346-
}
13471347

13481348
this.trigger('pre-body', data);
13491349

0 commit comments

Comments
 (0)