Results 1 to 4 of 4

Thread: Ext.data.field.convert functions

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
      0  

    Default Ext.data.field.convert functions

    When you assign a method do to a filed "convert" property, the scope is Window. It would be quite helpful if the scope was the Model class, so you could easily assign a method that is generic for more fields.

    Example:
    PHP Code:
    Ext.define('Ext.data.MyModel', {
        
    extend'Ext.data.Model',
        
    fields: [
            {
    name'field1'convertthis.mightyConvertFn},
            {
    name'field2'convertthis.mightyConvertFn}
        ],

         
    mightyConvertFn: function(v,r) { /* do something */ }
    }); 
    This is not possible right now, because in "convert: this.mightyConvertFn" is 'this' the Window object. Is it a bug or a feature? What do you think?

  2. #2
    Sencha User
    Join Date
    Sep 2011
    Posts
    574
    Vote Rating
    74
      2  

    Default

    Neither. It is the way JavaScript works. Even more, if you enable strict mode, your code won't be interpreted.
    If you need same convert for different fields consider creating a type.

  3. #3
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    72
    Vote Rating
    13
      1  

    Default

    To elaborate, you can't reference the Model class using "this" because the Model class doesn't exist yet.

    To create a type, you would do something like this.
    Code:
    Ext.data.Types.MYTYPE = {
        type:     'mytype',
        sortType: Ext.data.SortTypes.none,
        convert:  function mightyConvertFn(v, r) {
            /* do something */
        }
    };
    
    Ext.define('Ext.data.MyModel', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'field1', type: 'mytype'},
            {name: 'field2', type: 'mytype'}
        ]
    });

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
      0  

    Default

    I get it now, thanks guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •