在我的数据库中,我有一列 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';
}
}
您不需要更改模型。
在您的示例中,我认为您应该在模型中添加字段的类型。
{ name: 'Actif', type: 'boolean' }
关于javascript - GridBooleanColumn 数据首先为 0 和 1,但没有 true 和 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16887867/