Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Dec 2011
    Location
    Russia, Moscow
    Posts
    6
    Vote Rating
    0
    vvs is on a distinguished road

      0  

    Default [ST2.1] parent is array in nested XTemplate

    [ST2.1] parent is array in nested XTemplate


    ST version tested:
    • Ext 2.1
    Description:
    • in nested XTemplate parent returns array instead of object
    Test Case:

    Code:
            
    var tpl1 = new Ext.XTemplate(            
                '<tpl for=".">',
                    'a: {a}',
                        '<tpl for="b">',
                            '{% console.log(parent) %}',
                        '</tpl>',
                '</tpl>'
             ),
    
    
          tpl2 = new Ext.XTemplate(
                'a: {a}',
                    '<tpl for="b">',
                    '{% console.log(parent) %}',
                    '</tpl>'
             ),
             obj = { 'a': 'a', 'b': [{ 'c': 'c'}] };
    
    
            tpl1.apply(obj);
            tpl2.apply(obj);
    The result that was expected:

    In both bases object should be logged to console.

    The result that occurs instead:

    tpl1 - array is printed instead.
    • [Object]
      • 0: Object
        • a: "a"
        • b: Array[1]
        • __proto__: Object
        • length: 1
      • __proto__: Array[0]
    ‚Äč
    tpl2 - result is correct.
    • Object {a: "a", b: Array[1]}
      • a: "a"
      • b: Array[1]
      • __proto__: Object



  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    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


    Code:
    new Ext.XTemplate(
        '<tpl for=".">',
            'a: {a}',
            '<tpl for="b">',
                '{% console.log(parent) %}',
            '</tpl>',
        '</tpl>'
    )
    Is not valid for your object like:

    Code:
    {
        a : 'a',
        b : [
            {
                c : 'c'
            }
        ]
    }
    The reason is <tpl for=".">...</tpl> is told to iterate through an array but you are feeding it an object.
    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.

Thread Participants: 1