ExtJs Model之convert的使用

convert: function(value,record){}

value:为当前属性的值,record.get('属性')用来获取其他属性的值。

以下案例是:将年龄减去2。

Ext.define('MyModel', {

    extend: 'Ext.data.Model',

    fields: [

        {name: 'name', type: 'string'},

        {name: 'age', type: 'int',

            convert: function(value, record) {

                return value - 2;

            }

        }

    ]

});



var userStore = Ext.create('Ext.data.Store', {

    model: 'MyModel',

    data: [

        {name: '张三1', age: 25},

        {name: '张三2', age: 26},

        {name: '张三3', age: 27}

    ]

});



Ext.onReady(function() {

    Ext.create('Ext.grid.Panel', {

        renderTo: Ext.getBody(),

        store: userStore,

        width: 400,

        height: 200,

        title: 'Grid Panel',

        columns: [

            {

                text: 'Name',

                flex: 1,

                dataIndex: 'name'

            },

            {

                text: 'Age',

                flex: 1,

                dataIndex: 'age'

            }

        ]

    });

});

 

你可能感兴趣的:(convert)