javascript - GridBooleanColumn 数据首先为 0 和 1,但没有 true 和 false

标签 javascript extjs

在我的数据库中,我有一列 Actif,其值为 0 和 1(假和真)

我尝试使用列。我的数据库值为 0 和 1 的 bool 值...但它不起作用。

{
    xtype: 'booleancolumn',
    dataIndex: 'Actif',
    text: 'MyBooleanColumn',
    falseText: 'Non',
    trueText: 'Oui'
}

请帮助我:)

我的模型

Ext.define('ModuleGestion.model.UtilisateursApplicatifs', {
extend: 'Ext.data.Model',

fields: [
    {
        name: 'Nom'
    },
    {
        name: 'Prenom'
    },
    {
        name: 'Identification'
    },
    {
        name: 'MotDePasse'
    },
    {
        name: 'IUtilisateurApplicatif'
    },
    {
        name: 'FonctionRepertoire'
    },
    {
        name: 'FonctionAnimation'
    },
    {
        name: 'FonctionFormation'
    },
    {
        name: 'FonctionAdministration'
    },
    {
        name: 'Actif'
    }
]});

解决方案是删除返回值的双引号:

$resultat = json_encode($resultat ); 
$resultat = str_replace('"Actif":"0"', '"Actif":0', $resultat); 
$resultat = str_replace('"Actif":"1"', '"Actif":1', $resultat);

最佳答案

我有类似的情况,对于来自数据库的 0 和 1,我使用的不是 bool 列。我从 db 发送 0 和 1,在我的列渲染器中检查它并进行一些转换。检查我的示例(这里是操作列 - 用于在单元格中显示图标)。这是决定您的情况的一种方法。 我的看法:

xtype: 'actioncolumn',
width: 55,
align: 'center',
dataIndex: 'Actif',
menuDisabled: 'true'
text: '',
sortable: false,
fixed: 'true',
renderer: function (value, metadata, record) {
    if (value == '0') {
        //some code
    }
    else {
        //some code
    }
},
getTip: function (value, metadata, record) {
    if (value == '0') {
        return 'here 0';
    } else {
        return 'here 1';
    }
}

您不需要更改模型。

在您的示例中,我认为您应该在模型中添加字段的类型。

here's example

  { name: 'Actif', type: 'boolean' }

关于javascript - GridBooleanColumn 数据首先为 0 和 1,但没有 true 和 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16887867/

相关文章:

Javascript/ExtJS - 通过 textarea 获取 Codemirror Editor

00-59(秒)之间数字的javascript正则表达式

javascript - 如何使用 gantt-tooltip 属性在 Angular 表中以用户输入的格式显示日期

javascript - express JS : Cannot read property 'lazyrouter' of undefined

javascript - Extjs网格面板一列背景颜色更改另一列值

javascript - 将数据加载到商店后,Extjs 组合框为空

javascript - 如何在penal的extjs项中多次添加容器

javascript - JavaScript 原型(prototype)——使用构造函数的函数

javascript - "Error: this.setState is not a function"试图取消选中 React Native 中的 CheckBox?

javascript - 在 Sencha Touch 2.4.0 中实现路由