-
5 Apr 2012 11:28 AM #1
Answered: How do i call Model'smethod in tpl?
Answered: How do i call Model'smethod in tpl?
Hi there,
My model has a very complex function , like this
how do i call it inside a itemTpl? i tried this but failed {getFullName()}Code:getFullName: function() { returnthis.get(display_as'); }
Thanks
-
Best Answer Posted by mitchellsimoens
So call it from the template method. Issue is you don't have access to the record, just it's data.
-
5 Apr 2012 11:42 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,118
- Vote Rating
- 453
- Answers
- 3160
Are we in a list or a regular component?
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.
-
5 Apr 2012 12:32 PM #3
-
5 Apr 2012 2:44 PM #4
Check out the XTemplate doc: http://docs.sencha.com/touch/2-0/#!/api/Ext.XTemplate
Towards the bottom, there's one section about "Execute arbitrary inline code..." and one about "Template member functions". Maybe one of those will help?
-
5 Apr 2012 3:10 PM #5
thanks for the reply, but i want to use member functions from the model itself instead of xtemplate's inline functions.
-
5 Apr 2012 4:11 PM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,118
- Vote Rating
- 453
- Answers
- 3160
Here is a little test case:
Code:new Ext.dataview.List({ fullscreen : true, store : new Ext.data.Store({ fields : ['firstName', 'lastName'], data : [ { firstName : 'Mitchell', lastName : 'Simoens' } ] }), itemTpl : new Ext.XTemplate( '{firstName} {lastName} -> {[this.fullName(values)]}', { fullName : function(values) { return values.lastName + ', ' + values.firstName; } } ) });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.
-
6 Apr 2012 5:51 AM #7
No, i dont want to use' XTemplate's inline methods.
I rather want to you use Model's inner method.
Here is pseudo code of my problem:
Model Code
Code:Mode{ fields : [some fileds], getComplexValue(){ } }
View Class
I hope my situation is clear nowCode:View{ xtype: 'list', itemTpl: 'here is {getComplexValue()}' }
Thanks
-
6 Apr 2012 5:54 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,118
- Vote Rating
- 453
- Answers
- 3160
So call it from the template method. Issue is you don't have access to the record, just it's data.
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.
-
6 Apr 2012 6:04 AM #9
and how do i do that? (call Model's method via XTemplate's method)
sorry for my noobish questions, its my 3rd day with sencha .
-
6 Apr 2012 6:19 AM #10Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,118
- Vote Rating
- 453
- Answers
- 3160
As I said, you don't have access to the record, just it's data.
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.


Reply With Quote