浏览代码

行选择器功能优化

jqh 4 年之前
父节点
当前提交
c630986ae8
共有 1 个文件被更改,包括 7 次插入7 次删除
  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() {
     init() {
         let options = this.options,
         let options = this.options,
             checkboxSelector = options.checkboxSelector,
             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');
             $(this).parents(options.container).find(checkboxSelector).prop('checked', this.checked).trigger('change');
         });
         });
         if (options.clickRow) {
         if (options.clickRow) {
-            $checkbox.click(function (e) {
+            $document.on('click', checkboxSelector, function (e) {
                 if (typeof e.cancelBubble != "undefined") {
                 if (typeof e.cancelBubble != "undefined") {
                     e.cancelBubble = true;
                     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');
             var tr = $(this).closest('tr');
             if (this.checked) {
             if (this.checked) {
                 tr.css('background-color', options.background);
                 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 {
             } else {
                 tr.css('background-color', '');
                 tr.css('background-color', '');