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

      0  

    Default


    looks like ill have to move all those model methods to xtemplates, thanks.

  2. #12
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    closeboy,

    A solution, not necesarily memory freindly would be to reconstruct the model instance in a template method where only original model data would be available, as the others said already.
    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) { 
                //recreate model 
                var m = new YourModel(values); 
                //call your complex function 
                m.myComplexFunction(); 
                return values.lastName + ', ' + values.firstName; 
                } 
            } )
        }
        )
    Last edited by bluehipy; 6 Apr 2012 at 6:49 AM. Reason: misformat

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

      0  

    Default


    But then how would i reuse them on other views? I think the answer is to create a seperate XTemplate.js? Am i right?

  4. #14
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    606
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Creating a separate XTemplate.js is not a solution...

    You could extend XTemplate or use same instance of XTemplate in more views.

    If you are only a few days in Sencha Touch 2, spend some time with the provided tutorials , it will be of great help

    Some good tutorials but for Sencha 1 about templates are here:
    http://www.sencha.com/learn/xtemplates-part-i/
    http://www.sencha.com/learn/xtemplates-part-ii/

    I think most of the concepts are available for Sencha Touch 2 also.

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

      0  

    Default


    thanks for the links
    i'm not only new to sencha but also to javascript , so this is going to be a very noobish journey for me :P

  6. #16
    Sencha User
    Join Date
    Mar 2012
    Posts
    3
    Vote Rating
    0
    sapphous is on a distinguished road

      0  

    Default


    Not sure if there might be a better way, but I've been attempting to do this same thing, and here's what I did (though in my case I'm adding models to my store through store.add(), so if you're using proxies etc. you'll have to find your own place to put the equivalent code--also, be careful about sending self-referential objects through JSON--this may not work for your particular case):

    I added a field to my model to store a reference to itself. Then, whenever I create a model to put it into my store, I just do:

    Code:
    var theModel = Ext.create('myApp.model.myModel', {
        someField : 'Some Field Value'
    });
    theModel.set('selfReference', theModel);
    Ext.getStore('MyStore').add(theModel);
    Then I win. In my list's tpl, I can now just do something like {[values.selfReference.someFunction()]}.

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

      0  

    Default


    thanks

  8. #18
    Sencha User
    Join Date
    Aug 2010
    Posts
    17
    Vote Rating
    1
    pyoungerv is on a distinguished road

      0  

    Default


    this seems like a strange limitation. why doesnt xtemplate provide access to the passed record? i would like to do the same thing: call model methods. that would be a much cleaner code design. there appears to be very weak support for computed fields (on a related subject) because even convert is not useful for real time dynamic computed fields. has anyone tried to augment the xtemplate code to include a reference to the model?

  9. #19
    Sencha User
    Join Date
    Aug 2010
    Posts
    17
    Vote Rating
    1
    pyoungerv is on a distinguished road

      0  

    Default


    one more note. it looks to me like there is a bug in the code implementing the xindex and xcount variables. aren't they hard-coded to always be 1? i cant make them increment.

  10. #20
    Sencha User
    Join Date
    Aug 2010
    Posts
    17
    Vote Rating
    1
    pyoungerv is on a distinguished road

      1  

    Default decent solution?

    decent solution?


    i found something that works and feels at least somewhat safe. if anyone sees a better option or a potential for memory leak etc, pls let me know.

    i subclassed the list and overrode the prepareData method. note that i set a "rec" property on the template to the current record because the template is accessible in the {[template pseudo code]} because it gets the template passed as the scope.

    Code:
    Ext.define('Ext.ux.List', {
        extend : 'Ext.dataview.List',
        xtype : 'myList',
        prepareData: function(data,index,record){
            this.getItemTpl().rec = record;
            return this.callParent(arguments);
        },
    })
    in the template html i use:

    Code:
    {[this.rec.doYourThing()]}
    it would be nice if sencha saw to implementing support for a fuller contextual access inside of xtemplate code. i think that would be really helpful