浏览代码

Methods 'updateRow' and 'updateByUniqueId' can now take either a row or an array of rows as parameter

David Maison 10 年之前
父节点
当前提交
a7a0032ba5
共有 2 个文件被更改,包括 26 次插入15 次删除
  1. 2 2
      docs/_i18n/en/documentation/methods.md
  2. 24 13
      src/bootstrap-table.js

+ 2 - 2
docs/_i18n/en/documentation/methods.md

@@ -108,7 +108,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>updateRow</td>
         <td>updateRow</td>
         <td>params</td>
         <td>params</td>
         <td>
         <td>
-        Update the specified row, the param contains following properties: <br>
+        Update the specified row(s), each param contains following properties: <br>
         index: the row index to be updated. <br>
         index: the row index to be updated. <br>
         row: the new row data.
         row: the new row data.
         </td>
         </td>
@@ -117,7 +117,7 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>updateByUniqueId</td>
         <td>updateByUniqueId</td>
         <td>params</td>
         <td>params</td>
         <td>
         <td>
-        Update the specified row, the param contains following properties: <br>
+        Update the specified row(s), each param contains following properties: <br>
         id: a row id where the id should be the uniqueid field assigned to the table. <br>
         id: a row id where the id should be the uniqueid field assigned to the table. <br>
         row: the new row data.
         row: the new row data.
         </td>
         </td>

+ 24 - 13
src/bootstrap-table.js

@@ -2306,19 +2306,24 @@
     };
     };
 
 
     BootstrapTable.prototype.updateByUniqueId = function (params) {
     BootstrapTable.prototype.updateByUniqueId = function (params) {
-        var rowId;
+        var that = this;
+        var allParams = $.isArray(params) ? params : [ params ];
 
 
-        if (!params.hasOwnProperty('id') || !params.hasOwnProperty('row')) {
-            return;
-        }
+        $.each(allParams, function(i, params) {
+            var rowId;
+
+            if (!params.hasOwnProperty('id') || !params.hasOwnProperty('row')) {
+                return;
+            }
 
 
-        rowId = $.inArray(this.getRowByUniqueId(params.id), this.options.data);
+            rowId = $.inArray(that.getRowByUniqueId(params.id), that.options.data);
 
 
-        if (rowId === -1) {
-            return;
-        }
+            if (rowId === -1) {
+                return;
+            }
+            $.extend(that.data[rowId], params.row);
+        });
 
 
-        $.extend(this.data[rowId], params.row);
         this.initSort();
         this.initSort();
         this.initBody(true);
         this.initBody(true);
     };
     };
@@ -2335,10 +2340,16 @@
     };
     };
 
 
     BootstrapTable.prototype.updateRow = function (params) {
     BootstrapTable.prototype.updateRow = function (params) {
-        if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
-            return;
-        }
-        $.extend(this.data[params.index], params.row);
+        var that = this;
+        var allParams = $.isArray(params) ? params : [ params ];
+
+        $.each(allParams, function(i, params) {
+            if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
+                return;
+            }
+            $.extend(that.data[params.index], params.row);
+        });
+
         this.initSort();
         this.initSort();
         this.initBody(true);
         this.initBody(true);
     };
     };