1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    0
    clozeboy is on a distinguished road

      0  

    Default 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

    Code:
     
    getFullName: function() {           
         returnthis.get(display_as');
    }
    
    how do i call it inside a itemTpl? i tried this but failed {getFullName()}

    Thanks

  2. So call it from the template method. Issue is you don't have access to the record, just it's data.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Are we in a list or a regular component?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    0
    clozeboy is on a distinguished road

      0  

    Default


    in a list

  5. #4
    Sencha User
    Join Date
    Apr 2011
    Posts
    40
    Answers
    2
    Vote Rating
    2
    clubby is on a distinguished road

      0  

    Default


    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?

  6. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    0
    clozeboy is on a distinguished road

      0  

    Default


    thanks for the reply, but i want to use member functions from the model itself instead of xtemplate's inline functions.

  7. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by clozeboy View Post
    thanks for the reply, but i want to use member functions from the model itself instead of xtemplate's inline functions.
    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  8. #7
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    0
    clozeboy is on a distinguished road

      0  

    Default


    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
    Code:
    View{
         xtype: 'list',
         itemTpl: 'here is {getComplexValue()}'
    }
    I hope my situation is clear now
    Thanks

  9. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  10. #9
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Vote Rating
    0
    clozeboy is on a distinguished road

      0  

    Default


    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 .

  11. #10
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    As I said, you don't have access to the record, just it's data.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.