1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    2
    Vote Rating
    0
    ynhat is on a distinguished road

      0  

    Question Answered: Change value of component in DataItem when using dataMap

    Answered: Change value of component in DataItem when using dataMap


    I have Ext.Img component in DataItem. After getting url value from server, I want to add url of Sencha.io to it. Then, I set it as Img component src.

    Url value from server:
    images/someimage.jpg

    New url:
    http://src.sencha.io/60/60/http://my.../someimage.jpg

    Here is my code. It always gets the old value from server. Do anyone know the reason?
    Btw, is there any better approach for this?

    Code:
    Ext.define('ABC.view.HotDealItem', {
        extend : 'Ext.dataview.component.DataItem',
        xtype : 'hotdealitem',
        requires : ['Ext.Img'],
    
    
        config : {
            dataMap : {
                getImage : {
                    setSrc : 'image'
                }
            },
    
    
            image : {
                docked : 'left',
                xtype : 'image',
                cls : 'image'
            },
    
    
            layout : {
                type : 'vbox'
            }
        },
    
    
        applyImage : function(config) {
            return Ext.factory(config, Ext.Img, this.getImage());
        },
        updateImage : function(newImage, oldImage) {
            if(oldImage) {
                this.remove(oldImage);
            }
    
    
            if(newImage) {
                this.add(newImage);
            }
        },
        updateRecord : function(newRecord) {
            this.callParent(arguments);
    
    
            if(!newRecord) {
                return;
            }
    
    
            var image = this.getImage();
            image.setSrc('http://src.sencha.io/60/60/http://mydomain.com/' + newRecord.get('image'));
        }
    });

  2. Why not use the convert config in the field in the model? Change the URL up front.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    34,121
    Vote Rating
    453
    Answers
    3160
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Why not use the convert config in the field in the model? Change the URL up front.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    2
    Vote Rating
    0
    ynhat is on a distinguished road

      0  

    Default Use convert config to change or add new field to model

    Use convert config to change or add new field to model


    Thanks Mitchell.

    I follow your suggestion, and it works now. I upload my code below. Maybe, it will be helpful for someone.

    In the model, I still want to keep "image" field. Therefore, I create a new field named "image-s".

    Code:
    Ext.define('ABC.model.HotDeal', {
        extend : 'Ext.data.Model',
        requires : 'ABC.proxy.HotDeal',
    
    
        config : {
            fields : [
                {
                    name : "image",
                    type : "string"
                }, 
                {
                    name : "image-s",
                    type : "string",
                    convert : function(v, record) {
                        return 'http://src.sencha.io/60/60/http:/mydomain.com/' + record.data.image;
                    }
                }
            ],
    
    
            proxy : {
                type : 'hotdeal'
            }
        }
    });
    References:
    http://docs.sencha.com/touch/2-0/#!/...ld-cfg-convert

  5. #4
    Sencha User
    Join Date
    Sep 2007
    Posts
    3
    Vote Rating
    0
    towerhe is on a distinguished road

      0  

    Default


    I think that updateRecord is the right place to format the values for the dataitem. The representation of the data is a view logic, we should not do it in the domain models.

  6. #5
    Sencha User interfasys's Avatar
    Join Date
    Mar 2011
    Location
    UK & Switzerland
    Posts
    123
    Vote Rating
    1
    interfasys is on a distinguished road

      0  

    Default


    The updateRecord "way" works fine, especially after having removed the deprecated datamap config element.
    Olivier - interfaSys
    Developing custom solutions for BlackBerry 10 using Sencha Touch.

  7. #6
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    38
    Vote Rating
    1
    =NR= is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Why not use the convert config in the field in the model? Change the URL up front.
    i don't see this config in the documentation, am i missing something here?
    where can i find reference (what it used for, and bla bla) for this config property?

  8. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    34,121
    Vote Rating
    453
    Answers
    3160
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    The fields config setup the Ext.data.Field: http://docs.sencha.com/touch/2.2.0/#...ld-cfg-convert
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  9. #8
    Sencha User =NR='s Avatar
    Join Date
    Mar 2013
    Location
    Singapore
    Posts
    38
    Vote Rating
    1
    =NR= is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    The fields config setup the Ext.data.Field: http://docs.sencha.com/touch/2.2.0/#...ld-cfg-convert
    thanks mitchell

Tags for this Thread