-
23 Jan 2012 11:22 AM #1
Unanswered: Panel problem: setData & tpl
Unanswered: Panel problem: setData & tpl
Hi folks,
I've read this http://www.sencha.com/forum/showthre...-doesn-t-work&
and I've tried to implement it, but without lucky....
Can you help me? This is the code:
So.. I set TPL attribute to mypanel, I call a SetData in order to set data to mypanel,Code:Ext.define('DANode', { extend: 'Ext.data.Model', fields: [{ name: 'idn' },{ name: 'text' },{ name: 'dsc' },{ name: 'preview' }] }); MyPanel = new Ext.Panel({ layout: 'card', config: { styleHtmlContent: true, scrollable: true }, items:[{ xtype: 'panel', fullscreen: true, model: 'DANode', style: 'text-align: center;', tpl: 'Your name is: {preview}' }, new Ext.Carousel({ indicator: false, defaults: { scroll: 'vertical' } }) ] }) AND .... Ext.Ajax.request({ url: AJAX_REQUEST_URL2, success: function( response ){ mydata = { preview: 'aaaaaa' }; MyPanel.setData(mydata); }, ... omissis ... });
and if I follow debugger, I see that Sencha call a method to overwrite my panel data with a TPL response,
my nothing is showed on the screen...
Do you have any idea?
Thank so much.
-
23 Jan 2012 1:18 PM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,170
- Vote Rating
- 32
- Answers
- 83
A few issues with your code:
- Use Ext.create instead of new
- Do *not* use upper case for lexically scoped references. Uppercase initial letters are supposed to be for constructors and singletons.Last edited by rdougan; 23 Jan 2012 at 3:14 PM. Reason: removing update()

Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
23 Jan 2012 3:13 PM #3
The problem is that you are calling setData of myPanel, which is not the panel you set the tpl on. Unfortunately the data does not cascade into its children. So, you need to grab an reference of that inner panel and call setData on that.
Some other notes:
- You do not need to specify a model to use the tpl + data configurations.
- You only use the [i]config[/b] block when defining a class. When creating a class, you just put them in the object when you instantiate the component.
So this:
Turns into this:Code:MyPanel = new Ext.Panel({ layout: 'card', config: { styleHtmlContent: true, scrollable: true } });
Also as Jay mentioned, you should use Ext.create instead of the new keyword to create instances of classes. This means you can use our dependance management system (more information here).Code:MyPanel = new Ext.Panel({ layout: 'card', styleHtmlContent: true, scrollable: true });Sencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.
-
24 Jan 2012 3:50 AM #4
jay, rdougan thank you for your advices.
I've rewrite my code, but It doesn't works : (
This time I've:
I've noticed that when Sencha callCode:var nestedList = Ext.create('Ext.NestedList', { fullscreen: true, displayField: 'text', useTitleAsBackText: false, store: store, scrollable: false, getTitleTextTpl: ... omissis ..., getItemTextTpl: ... omissis ..., // provide a codebox for each source file getDetailCard: function(record, parentRecord) { // IMPORTANT CODE !!!!!!! return new Ext.create('Ext.Panel', { id: 'p1', layout: 'card', styleHtmlContent: true, scrollable: true, items:[{ xtype: 'panel', id: 'p2', fullscreen: true, style: 'text-align: center;', tpl: 'name: {name}', styleHtmlContent: true, scrollable: true, }] }); }, }) Ext.Ajax.request({ url: AJAX_REQUEST_URL2, success: function(response) { response = Ext.JSON.decode(response.responseText); data = { name: 'homer simpson' }; // detailCard is PANEL with id = P1 // detailCard.getItems().items[0] is Panel with id = P2 detailCard.getItems().items[0].setData(data); list.unmask(); }, ... omissis ... });
updater.call(this, value, oldValue);
value = { name: "homer simpson"} [ it is ok! ]
and
updater return html: "name: {name}" [ it is ok! ]
when Sencha call
el.innerHTML: "name: homer simpson"Code:overwrite: function(el, values, returnElement) { el = Ext.getDom(el); el.innerHTML = this.apply(values); return returnElement ? Ext.get(el.firstChild, true) : el.firstChild; }
but, in the end, nothing is displayed...
the last information:
if I use html attribute in panel P2, i.e:
html: 'name: homer simpson';
that works...
Maybe I've forgot something?
I must call a special function? ( an apply, update, dolayout or similar )
thanks again!Last edited by andrea.chiozzi@metislab.net; 24 Jan 2012 at 3:53 AM. Reason: I've removed MODEL code.. I don't need it : )
-
24 Jan 2012 4:08 AM #5
A very important discvery:
if in panel p2, I add:
it works!Code:xtype: 'panel', id: 'p2', fullscreen: true, style: 'text-align: center;', data: { name: 'homer simpson'}, <--------------------- NEW LINE! tpl: 'name: {name}', styleHtmlContent: true, scrollable: true,
so.. it is like if detailCard.getItems().items[0].setData(data); is not enough
but I've see with firebug that detailCard.getItems().items[0] is panel p2
and that setData(data) realy set { name: 'homer simpson' } on panel p2 o_O
I think that I've missed a step...
-
24 Jan 2012 10:25 AM #6
In your Ajax request, you use detailCard; but where does that come from?
Load the data into nested list, and do the following on the console:
Code:p = Ext.getCmp('p2'); p.getTpl(); //should return the correct tpl p.getData(); //should return the correct data (none) p.setData(); //should set the dataSencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.
-
24 Jan 2012 11:11 AM #7
Hi rdougan,
I've not write all my code because I don't want waste people time...
but I get detailCard in this way:
I've followed your advice .. and nw I can say that:Code:listeners: { leafitemtap: function(list, index, item, e) { var myStore = list.getStore(); <--- Start code readed in sencha forum var article = myStore.getAt(index); var me = list.getParent(); var detailCard = me.getDetailCard(); <--- End code readed in sencha forum list.setMask({ message: 'Loading' }); Ext.Ajax.request({ ..... ..... }) }
It is good.. but not enough .. nothig is displayed ...Code:p = Ext.getCmp('p2'); This returns my panel p.getTpl(); This returns my tpl ( html: "name: {name}" ) p.getData(); This returns null( no data in config ) p.setData(); This returns my panel with attribute _data = Object {name: 'homer simpson'} p.getData(); This returns Object {name: 'homer simpson'}

Bye
PS: I use sencha_v2_pr3 .. the last version ( I think )
-
21 Dec 2012 2:55 AM #8
have you found your problem? I have something similar in 2.1 maybe.


Reply With Quote