【问题标题】:Disable button if the selected row contains a specific value ng-grid如果所选行包含特定值 ng-grid,则禁用按钮
【发布时间】:2015-02-01 15:48:34
【问题描述】:

如果该行包含特定值,我正在尝试为我的网格禁用删除按钮。

我已经在我的 ng-disable 中为按钮设置了一个条件(并希望保留它),但我想添加第二个条件,例如:

mySelection.title == 'important'

如果我选择两行,这会如何表现?它不会遍历选定的行并检查这些行是否包含重要的标题,那么我该如何解决这个问题?

【问题讨论】:

    标签: javascript angularjs ng-grid


    【解决方案1】:

    ng-disabled 中使用function()

    对于 EX:

    <button ng-disabled="isDisabled(mySelection.title, parameter2)"> Remove </button>
    

    在控制器中,

     $scope.isDisabled = function(parameter1, parameter2) {
         // do your comparisons and return true or false 
    
         // for ex:
    
         // if(parameter1 == 'important' && parameter2 == 'spmeOtherValue') {
         //     return true;
         // } else {
         //     return false;
         // }
     }
    

    【讨论】:

    • return false 不影响 disabled 属性,即使 if 条件设置为 false,按钮仍然出现。
    猜你喜欢
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 2016-02-12
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    相关资源
    最近更新 更多