Results 1 to 3 of 3

Thread: component with tpl and setData()

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-1365 in a recent build.
  1. #1
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    631
    Vote Rating
    41
      0  

    Default component with tpl and setData()

    So the template renders correctly and the first setData() works as expected, but each additional call to setData() doesn't work. Keep clicking the button to see and look at the console to see that the data is actually changed.

    Code:
    Ext.application({
        name: 'App',
        
        total: 0,
        accountData: {
            name: 'Mike',
            inserted: 0
        },
        accountTpl: [
            '<div class="c-account-info">',
                '<div class="c-name">{name}</div>',
                '<div class="c-inserted-hdr">Cash Inserted</div>',
                '<div class="c-inserted">$ {inserted}</div>',
            '</div>'
        ],
    
    
        
        launch: function(options) {
            Ext.Viewport.setActiveItem({
                xtype: 'container',
                layout: {
                    type : 'vbox',
                    align: 'middle'
                },
    
    
                items: [{
                    xtype: 'component',
                    itemId: 'accountData',
                    tpl: this.accountTpl,
                    data: this.accountData
                }, {
                    xtype: 'button',
                    text: 'Click to add $5',
                    handler: function() {
                        var data = this.accountData;
    
    
                        this.total += 5;
                        data.inserted = this.total;
                        console.log(Ext.encode(data));
                        Ext.Viewport.down('#accountData').setData(data);
                    },
                    scope: this
                        
                }]
            })
        }
    });

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Vote Rating
    1381
      0  

    Default

    It looks like the object this.accountData and the object _data on your component are being shared meaning the data was not cloned. It works as expected when you do:

    Code:
    Ext.application({
        name: 'App',
    
        total: 0,
        accountData: {
            name: 'Mike',
            inserted: 0
        },
        accountTpl: [
            '<div class="c-account-info">',
                '<div class="c-name">{name}</div>',
                '<div class="c-inserted-hdr">Cash Inserted</div>',
                '<div class="c-inserted">$ {inserted}</div>',
            '</div>'
        ],
    
    
    
        launch: function(options) {
            Ext.Viewport.setActiveItem({
                xtype: 'container',
                layout: {
                    type : 'vbox',
                    align: 'middle'
                },
    
    
                items: [{
                    xtype: 'component',
                    itemId: 'accountData',
                    tpl: this.accountTpl,
                    data: this.accountData
                }, {
                    xtype: 'button',
                    text: 'Click to add $5',
                    handler: function() {
                        var data = Ext.apply({}, this.accountData);
    
    
                        this.total += 5;
                        data.inserted = this.total;
                        console.log(Ext.encode(data));
    
                        var cmp = Ext.Viewport.down('#accountData');
                        cmp.setData(data);
                    },
                    scope: this
    
                }]
            })
        }
    });
    I will still open this bug as we need to clone the object ourselves so this doesn't happen.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Ext JS Premium Member
    Join Date
    Apr 2010
    Location
    Omaha, NE
    Posts
    631
    Vote Rating
    41
      0  

    Default

    Thanks for the workaround. Put it in and it works now.

Posting Permissions

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