浏览代码

Update responseHandler and add examples.

zhixin 11 年之前
父节点
当前提交
1e13d7d67a
共有 3 个文件被更改,包括 50 次插入28 次删除
  1. 28 26
      docs/data4.json
  2. 17 1
      docs/examples.html
  3. 5 1
      src/bootstrap-table.js

+ 28 - 26
docs/data4.json

@@ -1,26 +1,28 @@
-[
-    {
-        "name": "Multiple Select",
-        "license": "The MIT License",
-        "description": "A jQuery plugin to select multiple elements with checkboxes :)",
-        "url": "<a href='https://github.com/wenzhixin/multiple-select'>https://github.com/wenzhixin/multiple-select</a>"
-    },
-    {
-        "name": "Bootstrap Table",
-        "license": "The MIT License",
-        "description": "Bootstrap table displays data in a tabular format and offers rich support to radio, checkbox, sort, pagination and so on. ",
-        "url": "<a href='https://github.com/wenzhixin/bootstrap-table'>https://github.com/wenzhixin/bootstrap-table</a>"
-    },
-    {
-        "name": "Bootstrap Show Password",
-        "license": "The MIT License",
-        "description": "Show/hide password plugin for bootstrap.",
-        "url": "<a href='https://github.com/wenzhixin/bootstrap-show-password'>https://github.com/wenzhixin/bootstrap-show-password</a>"
-    },
-    {
-        "name": "Blog",
-        "license": "The MIT License",
-        "description": "My blog",
-        "url": "<a href='https://github.com/wenzhixin/blog'>https://github.com/wenzhixin/blog</a>"
-    }
-]
+{
+    "repos": [
+        {
+            "name": "Multiple Select",
+            "license": "The MIT License",
+            "description": "A jQuery plugin to select multiple elements with checkboxes :)",
+            "url": "<a href='https://github.com/wenzhixin/multiple-select'>https://github.com/wenzhixin/multiple-select</a>"
+        },
+        {
+            "name": "Bootstrap Table",
+            "license": "The MIT License",
+            "description": "Bootstrap table displays data in a tabular format and offers rich support to radio, checkbox, sort, pagination and so on. ",
+            "url": "<a href='https://github.com/wenzhixin/bootstrap-table'>https://github.com/wenzhixin/bootstrap-table</a>"
+        },
+        {
+            "name": "Bootstrap Show Password",
+            "license": "The MIT License",
+            "description": "Show/hide password plugin for bootstrap.",
+            "url": "<a href='https://github.com/wenzhixin/bootstrap-show-password'>https://github.com/wenzhixin/bootstrap-show-password</a>"
+        },
+        {
+            "name": "Blog",
+            "license": "The MIT License",
+            "description": "My blog",
+            "url": "<a href='https://github.com/wenzhixin/blog'>https://github.com/wenzhixin/blog</a>"
+        }
+    ]
+}

+ 17 - 1
docs/examples.html

@@ -336,7 +336,7 @@
                 <h1 id="card-view">Card View Table</h1>
             </div>
             <div class="bs-example">
-                <table data-toggle="table" data-url="data4.json" data-height="246" data-card-view="true">
+                <table data-toggle="table" data-url="data4.json" data-height="246" data-card-view="true" data-response-handler="responseHandler">
                     <thead>
                     <tr>
                         <th data-field="name">Name</th>
@@ -346,6 +346,22 @@
                     </tr>
                     </thead>
                 </table>
+                <script>
+                    // client
+                    function responseHandler(res) {
+                        return res.repos;
+                    }
+
+                    // server
+                    /*
+                    function responseHandler(res) {
+                        return {
+                            rows: res.repos;
+                            total: res.repos.length
+                        }
+                    }
+                     */
+                </script>
             </div>
             <div class="highlight"><pre><code class="language-html"></code></pre></div>
 

+ 5 - 1
src/bootstrap-table.js

@@ -759,7 +759,11 @@
             success: function(res) {
                 var data = res;
 
-                res = that.options.responseHandler(res);
+                if (typeof that.options.responseHandler === 'function') {
+                    res = that.options.responseHandler(res);
+                } else if (typeof that.options.responseHandler === 'string') {
+                    res = eval(that.options.responseHandler + '(res)');
+                }
 
                 if (that.options.sidePagination === 'server') {
                     that.options.totalRows = res.total;