-
22 Dec 2011 10:49 AM #1
Using member functions to render the complex content
Using member functions to render the complex content
I need a component that shows info about offer. The best way i can thin of is to subclass the panel, create a template and set data for the panel. I achieved all that, but the template is not working as I'd like it to:
However it does not understand that I actually want to call a member function, not get the value if this.something variable.Code:new Ext.XTemplate( '<img src="{this.getImageUrl(images)}" width="120" height="120" />', '<div>', '<strong>€ {this.formatPrice(price)}</strong>', '<span class="name">{name}</span>', '<p>{description}</p>', '</div>', '<div class="info">', '<span class="type">{this.renderType(isOffer, isPrivate)}</span>', '<span class="type">{this.renderDistance(distance)}</span>', '</div>', { getImageUrl: function (images) { return CJ.constants.DEFAULT_DEAL_IMAGE; }, formatPrice: function (price) { return price; }, renderType: function (isOffer, isPrivate) { if (isPrivate == 'false') { return CJ.t('Business deal') } if (isOffer == 'true') { return CJ.t('Offer'); } return CJ.t('Search'); }, renderDistance: function (dist) { return (dist - 0) + 'm'; } })
Is there a way to make it work as I want it to?
-
22 Dec 2011 11:24 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,640
- Vote Rating
- 435
You need to surround it with square brackets:
Code:{[this.renderType(isOffer, isPrivate)]}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.
-
23 Dec 2011 6:25 AM #3
Is there any official documentation where I can see these options?
I read everything about XTemplate, but did not find that.
Also there is a problem in the code above. If you're passing values as parameter, you should use
instead ofCode:{[this.renderType(values.isOffer, values.isPrivate)]}
Code:{[this.renderType(isOffer, isPrivate)]}





Reply With Quote