浏览代码

Merge pull request #1573 from tmazur/unique-id-in-row-data-property

UniqueId can also be stored in a row's data property
文翼 10 年之前
父节点
当前提交
e241028e3f
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11 7
      src/bootstrap-table.js

+ 11 - 7
src/bootstrap-table.js

@@ -2159,26 +2159,30 @@
         var uniqueId = this.options.uniqueId,
             len = this.options.data.length,
             dataRow = null,
-            i, row;
+            i, row, rowUniqueId;
 
         for (i = len - 1; i >= 0; i--) {
             row = this.options.data[i];
 
-            if (!row.hasOwnProperty(uniqueId)) {
+            if (row.hasOwnProperty(uniqueId)) { // uniqueId is a column
+                rowUniqueId = row[uniqueId];
+            } else if(row._data.hasOwnProperty(uniqueId)) { // uniqueId is a row data property
+                rowUniqueId = row._data[uniqueId];
+            } else {
                 continue;
             }
 
-            if (typeof row[uniqueId] === 'string') {
+            if (typeof rowUniqueId === 'string') {
                 id = id.toString();
-            } else if (typeof row[uniqueId] === 'number') {
-                if ((Number(row[uniqueId]) === row[uniqueId]) && (row[uniqueId] % 1 === 0)) {
+            } else if (typeof rowUniqueId === 'number') {
+                if ((Number(rowUniqueId) === rowUniqueId) && (rowUniqueId % 1 === 0)) {
                     id = parseInt(id);
-                } else if ((row[uniqueId] === Number(row[uniqueId])) && (row[uniqueId] !== 0)) {
+                } else if ((rowUniqueId === Number(rowUniqueId)) && (rowUniqueId !== 0)) {
                     id = parseFloat(id);
                 }
             }
 
-            if (row[uniqueId] === id) {
+            if (rowUniqueId === id) {
                 dataRow = row;
                 break;
             }