如何在 AngularJS 中显示 Yes/No 而不是 True/False [英] How to display Yes/No instead of True/False in AngularJS

查看:34
本文介绍了如何在 AngularJS 中显示 Yes/No 而不是 True/False的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cellTemplate在网格中显示数据,现在我必须在ng-grid中显示数据,我可以在其中显示一列中包含真值或假值的数据,请指导我如何显示真值或错误数据,如是或否,即,对于真值,我必须显示是,而对于假值,我必须显示为否.请指导我进行哪些更改才能获得所需的结果.

解决方案

创建一个简单的过滤器,例如:

app.filter('true_false', function() {返回函数(文本,长度,结束){如果(文本){返回是";}返回否";}});

并在您的 cellTemplate(或您想要的任何地方)中使用它:

cellTemplate: '

{{row.getProperty(col.field) |true_false}}</div>'

这是一个 Plunker

I am using the cellTemplate to display the data in grid ,now i have to display the data in ng-grid ,where i can display the data containing true or false value in one column ,please guide me how to display the true or false data like yes or no ,i.e ,for true value i have to display yes and for false value to no .please guide me what changes in makes my required result.

解决方案

Create a simple filter like:

app.filter('true_false', function() {
    return function(text, length, end) {
        if (text) {
            return 'Yes';
        }
        return 'No';
    }
});

and use it in your cellTemplate (or wherever you want):

cellTemplate: '<div class="ngCellText">{{row.getProperty(col.field) | true_false}}</div>'

Here is a Plunker

这篇关于如何在 AngularJS 中显示 Yes/No 而不是 True/False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆