PDA

View Full Version : Problem using hasMany in custom XTemplate



jugg1es
9 Aug 2012, 11:20 AM
I have a store that is filled dynamically (so it doesn't have a proxy) that has a 'hasMany' association to a different model.



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



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


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?

jugg1es
9 Aug 2012, 11:46 AM
Well I made a change that inexplicably fixed the problem. I removed id="{CategoryName}" from this 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:

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