ExtJS列数据转换
我从RESTAPI获取数据,返回数据,其中一列是status of group,在数据库中定义为integer,我想在UI中显示之前将其转换为string。例如,RESTAPI返回的状态为1,但我希望显示为“Valid”。。。但我不知道转换将在哪里进行。我是否应该将int->string的转换保存在存储中,或者在何处执行此转换。请帮忙。ExtJS列数据转换,extjs,Extjs,我从RESTAPI获取数据,返回数据,其中一列是status of group,在数据库中定义为integer,我想在UI中显示之前将其转换为string。例如,RESTAPI返回的状态为1,但我希望显示为“Valid”。。。但我不知道转换将在哪里进行。我是否应该将int->string的转换保存在存储中,或者在何处执行此转换。请帮忙。 这是我的模型: // Model Ext.define('Console.model.Group', { extend: 'Ext.data.Model',
这是我的模型:
// Model
Ext.define('Console.model.Group', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'string'
}, {
name: 'group',
type: 'string'
}, {
name: 'state',
type: 'string'
}],
proxy: {
type: 'rest',
url: '/api/groups', // Joanne need to change the URL name here
reader: 'json'
}
});
// store
Ext.define('Console.store.Groups', {
extend: 'Ext.data.Store',
model: 'Console.model.Group',
autoSync: false,
buffered: false,
pageSize: 1000,
autoLoad: false,
autoDestory: true,
purgePageCount: 3,
sorters: [{
property: 'label',
}],
trailingBufferZone: 100,
proxy: {
simpleSortMode: true,
type: 'rest',
url: '/api/groups',
reader: {
type: 'json',
root: 'data',
totalProperty: 'total'
}
}
});
如果要在多个位置使用该映射,则最方便的方法是进行映射/转换,并在模型上创建一个虚拟字段:
{
name: 'statusText',
mapping: 'status',
convert: function(v, record) {
var map = {0:'Invalid', 1: 'Valid};
return map[v];
}
}
视情况而定。如果您只打算将其用作字符串,而从不需要int值,请在模型级别执行此操作。如果希望仅以这种方式显示网格,请使用列渲染器。