-
10 Jan 2012 1:54 PM #1
component with tpl and setData()
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 }] }) } });
-
11 Jan 2012 6:56 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
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:
I will still open this bug as we need to clone the object ourselves so this doesn't happen.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 }] }) } });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.
-
11 Jan 2012 7:22 AM #3
Thanks for the workaround. Put it in and it works now.
Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-1365
in
2.0.


Reply With Quote