Gelmiş geçmiş en büyük porno sitemiz olan 2pe de her zaman en kaliteli pornoları sunmayı hedefledik. Diğer video sitemiz olan vuam da ise hd porno ağırlıklı çalışmalara başladık.

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    44
    Answers
    4
    Vote Rating
    1
    jcoenrae is on a distinguished road

      0  

    Default Answered: Return values with model member function

    Answered: Return values with model member function


    Hello,

    I want to create a member function in a model and use that function in a template (which uses that model). My member function gets called but the returned value isn't shown.

    This is my model with function (note that the console.logs print the correct output):
    Code:
    app.models.Route = Ext.regModel("app.models.Route", {					        fields: [
    {name: "routeName", type: "string"},
    {name: "fromCity", type: "string"},
    {name: "toCity", type: "string"},
    {name: "custom", type:"bool"}],									  
    getTitle: function() {
    if(this.get('custom')){
    console.log(this.get('fromCity') + " - " + this.get('toCity'));
    return this.get('fromCity') + " - " + this.get('toCity');
    }else{
    console.log(this.get('routeName'));
    return this.get('routeName');
    }
    }});
    This is the template where I use the methods on the object. I just see Title:, and then nothing else.
    Code:
    app.views.routeTemplate = new Ext.XTemplate('<p>Title: {[this.getTitle]}</p>');
    Is it even possible to do this, because I couldn't find any examples of this.

    Kind regards,

    Jolien

  2. I couldn't find the correct way to do it, so I just added the methods to the template too and then it worked.

  3. #2
    Touch Premium Member
    Join Date
    Mar 2011
    Location
    New Jersey, USA
    Posts
    130
    Answers
    4
    Vote Rating
    0
    jjerome is on a distinguished road

      0  

    Default


    This is the template where I use the methods on the object. I just see Title:, and then nothing else.
    Code:

    app.views.routeTemplate = new Ext.XTemplate('<p>Title: {[this.getTitle]}</p>');
    what is your reference to 'this'?

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    44
    Answers
    4
    Vote Rating
    1
    jcoenrae is on a distinguished road

      0  

    Default


    Code:
    this
    is an object of the model.

    For example
    Code:
    {fromCity: "City from", 
    														 toCity: "City to", 
     custom: true,
    routeName: "Name"}
    It is loaded in a store and then the template is updated with the object. If I call the fields (for example
    Code:
    {fromCity}
    in the template, everything works well. The
    Code:
    this
    was just a try, it was the only time that my function was actually called.

  5. #4
    Touch Premium Member
    Join Date
    Mar 2011
    Location
    New Jersey, USA
    Posts
    130
    Answers
    4
    Vote Rating
    0
    jjerome is on a distinguished road

      0  

    Default


    I know that, that wasn't my question.. When you run through the debugger and when your XTemplate is being instantiated, what is 'this' referencing?

    Also try adding a () on the getTitle?

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    44
    Answers
    4
    Vote Rating
    1
    jcoenrae is on a distinguished road

      0  

    Default


    Hi,

    I'm using XCode because I'm building an iOS application and I cannot set any breakpoints in the javascript code there to see what the this object is referencing to.

    If I add () to the getTitle, the panel won't show anymore and the member method isn't called.

    Kind regards,

    Jolien

  7. #6
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    44
    Answers
    4
    Vote Rating
    1
    jcoenrae is on a distinguished road

      0  

    Default


    I noticed that values.getTitle gives the same result as this.getTitle, adding ()'s also results in the panel not showing up.

  8. #7
    Touch Premium Member
    Join Date
    Mar 2011
    Location
    New Jersey, USA
    Posts
    130
    Answers
    4
    Vote Rating
    0
    jjerome is on a distinguished road

      0  

    Default


    try referencing the model directly when you make the call 'getTitle'?

  9. #8
    Sencha User
    Join Date
    Aug 2011
    Location
    Belgium
    Posts
    44
    Answers
    4
    Vote Rating
    1
    jcoenrae is on a distinguished road

      0  

    Default


    I couldn't find the correct way to do it, so I just added the methods to the template too and then it worked.

Thread Participants: 1

Tags for this Thread