Browse Source

Merge pull request #724 from djhvscf/master

Fixing the issues of flatJSON
文翼 10 years ago
parent
commit
30db94b887
1 changed files with 22 additions and 9 deletions
  1. 22 9
      src/extensions/flatJSON/bootstrap-table-flatJSON.js

+ 22 - 9
src/extensions/flatJSON/bootstrap-table-flatJSON.js

@@ -35,24 +35,37 @@
 (function ($) {
     'use strict';
 
+    var flatJSON = function (el, data) {
+        if (el.options.flat) {
+            el.options.data = sd.flatHelper(data);
+        }
+        if (el.options.sidePagination === 'server') {
+            el.data = el.options.data;
+        }
+    };
+
     $.extend($.fn.bootstrapTable.defaults, {
         flat: false
     });
 
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
-        _initData = BootstrapTable.prototype.initData;
+        _initData = BootstrapTable.prototype.initData,
+        _init = BootstrapTable.prototype.init,
+        _load = BootstrapTable.prototype.load;
 
     BootstrapTable.prototype.initData = function () {
+        flatJSON(this, this.options.data);
+        _initData.apply(this, Array.prototype.slice.apply(arguments));
+    };
 
-        //If the flat is true
-        if (this.options.flat) {
-            this.options.data = sd.flatHelper(this.options.data);
-        }
-        if (this.options.sidePagination === 'server') {
-            this.data = this.options.data;
-        }
+    BootstrapTable.prototype.init = function () {
+        flatJSON(this, this.options.data);
+        _init.apply(this, Array.prototype.slice.apply(arguments));
+    };
 
-        _initData.apply(this, Array.prototype.slice.apply(arguments));
+    BootstrapTable.prototype.load = function (data) {
+        flatJSON(this, this.options.data);
+        _load.apply(this, Array.prototype.slice.apply(arguments));
     };
 
     //Main functions