Browse Source

行选择器功能优化

jqh 4 years ago
parent
commit
c630986ae8
1 changed files with 7 additions and 7 deletions
  1. 7 7
      resources/assets/dcat/js/extensions/RowSelector.js

+ 7 - 7
resources/assets/dcat/js/extensions/RowSelector.js

@@ -22,14 +22,14 @@ export default class RowSelector {
     init() {
         let options = this.options,
             checkboxSelector = options.checkboxSelector,
-            $selectAll = $(options.selectAllSelector),
-            $checkbox = $(checkboxSelector);
+            $document = $(document),
+            selectAll = options.selectAllSelector;
 
-        $selectAll.on('change', function() {
+        $document.on('change', selectAll, function() {
             $(this).parents(options.container).find(checkboxSelector).prop('checked', this.checked).trigger('change');
         });
         if (options.clickRow) {
-            $checkbox.click(function (e) {
+            $document.on('click', checkboxSelector, function (e) {
                 if (typeof e.cancelBubble != "undefined") {
                     e.cancelBubble = true;
                 }
@@ -41,13 +41,13 @@ export default class RowSelector {
             });
         }
 
-        $checkbox.on('change', function () {
+        $document.on('change', checkboxSelector, function () {
             var tr = $(this).closest('tr');
             if (this.checked) {
                 tr.css('background-color', options.background);
 
-                if ($(checkboxSelector + ':checked').length === $checkbox.length) {
-                    $selectAll.prop('checked', true)
+                if ($(checkboxSelector + ':checked').length === $(checkboxSelector).length) {
+                    $(selectAll).prop('checked', true)
                 }
             } else {
                 tr.css('background-color', '');