Results 1 to 2 of 2

Thread: Problem using hasMany in custom XTemplate

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    29
    Answers
    2

    Default Answered: Problem using hasMany in custom XTemplate

    I have a store that is filled dynamically (so it doesn't have a proxy) that has a 'hasMany' association to a different model.

    Code:
    Ext.define('W5.model.DisplayedCategoryModel', {
        extend: 'Ext.data.Model',
    hasMany: {
                model:'W5.model.DisplayedStatementsModel', 
                name: 'statements', 
            }
    }
    I fill the association manually when the data has been compiled


    Code:
    var groupedStatements = this.getGroupedStatementsStore();
    groupedStatements.each(function(cat) {
        var s = cat.statements();
            s.add({data});
    });
    I am trying to use the 'statements' association in an XTemplate

    Code:
    Ext.XTemplate(
                    '<tpl for=".">',
                       '<div class="category" id="{CategoryName}">',
                        '<div >{CategoryName}</div>',    
                         	'</div>',
                           '<tpl for="statements">',
                            '{Text}',
                        '</tpl>',
                    '</tpl>');
    The problem is that the template never shows the statements, but it appears as though the data is there. I think it's because the store isn't synched, but when I call sync() on the store, it throws an error. What am I doing wrong?

  2. Well I made a change that inexplicably fixed the problem. I removed id="{CategoryName}" from this code:

    Code:
    var template = new Ext.XTemplate(             
                           '<tpl for=".">',
                        '<div class="category" id="{CategoryName}">',
                        '<div >{CategoryName}</div>',            
                           '</div>',
                           '<tpl for="statements">',
                            '{Text}',
                        '</tpl>',
                    '</tpl>');
    so it now looks like this:
    Code:
    var template = new Ext.XTemplate(
                    '<tpl for=".">',
                        '<div class="category">',
                        '<div >{CategoryName}</div>',            
                           '</div>',
                           '<tpl for="statements">',
                            '{Text}',
                        '</tpl>',
                    '</tpl>');
    It now works and I have no idea why. Oh well

  3. #2
    Sencha User
    Join Date
    Jul 2012
    Posts
    29
    Answers
    2

    Default

    Well I made a change that inexplicably fixed the problem. I removed id="{CategoryName}" from this code:

    Code:
    var template = new Ext.XTemplate(             
                           '<tpl for=".">',
                        '<div class="category" id="{CategoryName}">',
                        '<div >{CategoryName}</div>',            
                           '</div>',
                           '<tpl for="statements">',
                            '{Text}',
                        '</tpl>',
                    '</tpl>');
    so it now looks like this:
    Code:
    var template = new Ext.XTemplate(
                    '<tpl for=".">',
                        '<div class="category">',
                        '<div >{CategoryName}</div>',            
                           '</div>',
                           '<tpl for="statements">',
                            '{Text}',
                        '</tpl>',
                    '</tpl>');
    It now works and I have no idea why. Oh well

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •