ExtJS列数据转换

时间:2015-06-22 02:15:42

标签: extjs

我从REST API获取数据返回数据,其中一列是group的状态,这在数据库中定义为整数,我想在将它们显示在UI中之前将其转换为字符串。例如,REST API的状态返回值为1,但我希望显示为"有效" ......但不知道转换将在何处发生。我应该在商店中转换来自int-> string ,还是应该在哪里进行转换。请帮忙。
这是我的模特:

// 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'
       }
   }
});

1 个答案:

答案 0 :(得分:1)

如果您想要在多个地方使用该映射,那么最方便的做法是进行映射/转换并在您的模型上创建虚拟字段:

       {
             name: 'statusText',
             mapping: 'status',
             convert: function(v, record) {
                    var map = {0:'Invalid', 1: 'Valid};
                    return map[v];
             }
        }
相关问题