Browse Source

这样就可以支持访问JSON嵌套属性了

Flat JSON 扩展不行啊,破坏了原始数据,大概看了下还是从这里下手不会影响,这样可行的话就太好了
John Zhang 10 years ago
parent
commit
d654c8fe02
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/bootstrap-table.js

+ 11 - 2
src/bootstrap-table.js

@@ -1335,6 +1335,15 @@
         var that = this,
             html = [],
             data = this.getData();
+        
+        function getItemField(item, field) {
+            var props = field.split('.');
+            var value = item;
+            for(var p in props) {
+                value = value[props[p]];
+            }
+            return value;
+        }
 
         this.trigger('pre-body', data);
 
@@ -1410,7 +1419,7 @@
 
             $.each(this.header.fields, function (j, field) {
                 var text = '',
-                    value = item[field],
+                    value = getItemField(item, field),
                     type = '',
                     cellStyle = {},
                     id_ = '',
@@ -1537,7 +1546,7 @@
                 index = $td[0].cellIndex,
                 field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
                 colomn = that.columns[getFieldIndex(that.columns, field)],
-                value = item[field];
+                value = getItemField(item, field);
 
             if ($td.find('.detail-icon').length) {
                 return;