Browse Source

#223: update bootstrap-table-flatJSON extension.

zhixin 11 years ago
parent
commit
cace63bf55
3 changed files with 81 additions and 70 deletions
  1. 26 17
      docs/data5.json
  2. 6 6
      docs/extensions.html
  3. 49 47
      src/extensions/flatJSON/bootstrap-table-flatJSON.js

+ 26 - 17
docs/data5.json

@@ -1,19 +1,28 @@
 [
 [
-	{
-		"id": 
-		{
-			"id2":'1'
-		},
-		"name": 
-		{
-			"name2": 'Item 1'
-		},
-		"price": 
-		{
-			"price2":
-			{
-				"price3":'$90'
-			}
-	   }
-   }
+    {
+        "id": {
+            "id2": "1"
+        },
+        "name": {
+            "name2": "Item 1"
+        },
+        "price": {
+            "price2": {
+                "price3": "$90"
+            }
+        }
+    },
+    {
+        "id": {
+            "id2": "2"
+        },
+        "name": {
+            "name2": "Item 2"
+        },
+        "price": {
+            "price2": {
+                "price3": "$91"
+            }
+        }
+    }
 ]
 ]

+ 6 - 6
docs/extensions.html

@@ -256,8 +256,8 @@
 
 
                 <div class="highlight"><pre><code class="language-html"></code></pre></div>
                 <div class="highlight"><pre><code class="language-html"></code></pre></div>
 				
 				
-				<div class="page-header">
-                    <h1 id="filter">Flat JSON object</h1>
+		<div class="page-header">
+                    <h1 id="flatJSON">Flat JSON object</h1>
                 </div>
                 </div>
 
 
                 <p data-es="Use el plugin: <a href='https://github.com/djhvscf/bootstrap-table-flatJSON' target='_blank'>bootstrap-table-flatJSON</a>">
                 <p data-es="Use el plugin: <a href='https://github.com/djhvscf/bootstrap-table-flatJSON' target='_blank'>bootstrap-table-flatJSON</a>">
@@ -265,17 +265,17 @@
                 </p>
                 </p>
 
 
                 <div class="page-header">
                 <div class="page-header">
-                    <h2 id="filter-usage" data-es="Uso">Usage</h2>
+                    <h2 id="flatJSON-usage" data-es="Uso">Usage</h2>
                 </div>
                 </div>
 
 
                 <div class="highlight highlight-html"><pre><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"extensions/filter/bootstrap-table-flatJSON"</span><span class="nt">&gt;&lt;/script&gt;</span>
                 <div class="highlight highlight-html"><pre><span class="nt">&lt;script </span><span class="na">src=</span><span class="s">"extensions/filter/bootstrap-table-flatJSON"</span><span class="nt">&gt;&lt;/script&gt;</span>
 </pre></div>
 </pre></div>
 
 
                 <div class="page-header">
                 <div class="page-header">
-                    <h2 id="filter-options" data-es="Opciones">Options</h2>
+                    <h2 id="flatJSON-options" data-es="Opciones">Options</h2>
                 </div>
                 </div>
 
 
-                <table data-toggle="table" data-show-toggle="true" class="table">
+                <table data-toggle="table" data-show-toggle="true">
                     <thead>
                     <thead>
                     <tr>
                     <tr>
                         <th>Name</th>
                         <th>Name</th>
@@ -297,7 +297,7 @@
                 </table>
                 </table>
 
 
                 <div class="page-header">
                 <div class="page-header">
-                    <h2 id="filter-demos" data-zh="示例" data-es="Ejemplos">Examples</h2>
+                    <h2 id="flatJSON-demos" data-zh="示例" data-es="Ejemplos">Examples</h2>
                 </div>
                 </div>
 
 
                 <div class="bs-example">
                 <div class="bs-example">

+ 49 - 47
src/extensions/flatJSON/bootstrap-table-flatJSON.js

@@ -1,4 +1,4 @@
-/ /**
+/**
  * bootstrap-table-flatJSON.js
  * bootstrap-table-flatJSON.js
  * @version: v1.0.0
  * @version: v1.0.0
  * @author: Dennis Hernández
  * @author: Dennis Hernández
@@ -31,7 +31,7 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  * OTHER DEALINGS IN THE SOFTWARE.
  */
  */
- 
+
 (function ($) {
 (function ($) {
     'use strict';
     'use strict';
 
 
@@ -43,51 +43,53 @@
         _initData = BootstrapTable.prototype.initData;
         _initData = BootstrapTable.prototype.initData;
 
 
     BootstrapTable.prototype.initData = function () {
     BootstrapTable.prototype.initData = function () {
-	
+
         _initData.apply(this, Array.prototype.slice.apply(arguments));
         _initData.apply(this, Array.prototype.slice.apply(arguments));
-		var that = this;
-		
-		//If the flat is true
-		if(that.options.flat) {
-			that.options.data = sd.flatHelper(that.options.data);
-		}
+        var that = this;
+
+        //If the flat is true
+        if (that.options.flat) {
+            that.options.data = sd.flatHelper(that.options.data);
+        }
+    };
+
+    //Main functions
+    var sd = {
+        flat: function (element) {
+            var result = {};
+
+            function recurse(cur, prop) {
+                if (Object(cur) !== cur) {
+                    result[prop] = cur;
+                } else if (Array.isArray(cur)) {
+                    for (var i = 0, l = cur.length; i < l; i++) {
+                        recurse(cur[i], prop ? prop + "." + i : "" + i);
+                        if (l == 0) {
+                            result[prop] = [];
+                        }
+                    }
+                } else {
+                    var isEmpty = true;
+                    for (var p in cur) {
+                        isEmpty = false;
+                        recurse(cur[p], prop ? prop + "." + p : p);
+                    }
+                    if (isEmpty) {
+                        result[prop] = {};
+                    }
+                }
+            }
+
+            recurse(element, "");
+            return result;
+        },
+
+        flatHelper: function (data) {
+            var flatArray = [];
+            $.each(data, function (i, element) {
+                flatArray.push(sd.flat(element));
+            });
+            return flatArray;
+        }
     };
     };
-	
-	//Main functions
-	var sd = {
-			flat: function(element) {
-				var result = {};
-				function recurse (cur, prop) {
-					if (Object(cur) !== cur) {
-						result[prop] = cur;
-					} else if (Array.isArray(cur)) {
-						for(var i = 0, l = cur.length; i < l; i++) {
-							recurse(cur[i], prop ? prop+"."+i : ""+i);
-							if (l == 0) {
-								result[prop] = [];
-							}
-						}
-					} else {
-						var isEmpty = true;
-						for (var p in cur) {
-							isEmpty = false;
-							recurse(cur[p], prop ? prop+"."+p : p);
-						}
-						if (isEmpty) {
-							result[prop] = {};
-						}
-					}
-				}
-				recurse(element, "");
-				return result;
-			},
-			
-			flatHelper: function (data) {
-				var flatArray = [];
-				$.each(data, function(i, element) {
-					flatArray.push(sd.flat(element));
-				});
-				return flatArray;
-			}
-		};
 })(jQuery);
 })(jQuery);