【问题标题】:how to hide the element in template based on another field's value - kendoui grid如何根据另一个字段的值隐藏模板中的元素 - kendoui 网格
【发布时间】:2016-08-25 10:08:54
【问题描述】:

我有一个专栏如下。

var commentsTemplate = "<input class='comments-button' type='image' src='images/comments_button.png'/>#: COMMENTS #";

{ "field": "COMMENTS", "title": "Comments", "template": matcher_comments_template},
{ "field": "TYPE", "title": "Type"},

我希望输入元素根据 TYPE 字段的值动态显示和隐藏。例如,如果 type 为 Good,则隐藏按钮,如果 type 为 Not Good,则显示按钮。有什么想法吗?

谢谢

【问题讨论】:

    标签: javascript jquery angularjs kendo-ui kendo-grid


    【解决方案1】:

    使用ng-show:

    var commentsTemplate = "<input class='comments-button' type='image' src='images/comments_button.png' ng-show="{{currentValue.title == "Good"}}"/>#: COMMENTS #";
    

    假设 currentValue 是您的主要 javascript 对象 ({ "field": "TYPE", "title": "Type"},) 存储的父对象。

    编辑 1

    OP 要求一个不绑定变量的实现。 我怎么能认为它是控制器中的“自制观察者”:

    <input class='comments-button' type='image' src='images/comments_button.png' ng-show="shouldShowMe()"/>
    

    并且,在控制器中:

    $scope.shouldShowMe = function(){
      return title == "Good";
    }
    

    【讨论】:

    • 如果没有绑定ng-model,还有其他方法吗?谢谢
    • 为您执行此操作的指令。我会编辑我的帖子给你看一个例子
    • 我很抱歉,但我认为如果不参考至少您的控制器或使用 jquery 是不可能的。您可以引用您的控制器或添加 jquery 作为依赖项吗?
    猜你喜欢
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多