PDA

View Full Version : dataview, template member function not working correct?



EducatedFool
30 Dec 2011, 10:11 AM
Hello there,

I have a dataview that loads some 'points' from a store and shows it in a template. At the end of the template I want to show the totalPoints. That's why I made a function 'addPoints' in the template-loop. And I call the totalPoints with 'getTotal'.

Now the problem is the 'totalPoints'. If I call new app.views.testView(); only once, it shows me
5
10
12
total: 27

If I do a new call after that new app.views.testView(); it shows me:
5
10
12
total: 54

the output of the console.log in the example makes it even stranger:
one call: 5 - 10 - 12
two calls: 5 - 10 -12 - 5 -10 -12 and 5 - 10 - 12 - 5 -10 -12 (two times the whole bunch)



Ext.regModel("TestModel", {
fields: [{name: "points", type: "int"}]
});
Ext.regStore("TestStore", {
model: "TestModel"
,proxy: {
type: 'scripttag'
,id: 'ranking-app-getit'
,url: Settings.url + '/ranking/getit
}
,autoLoad: false
});
app.views.testView = Ext.extend(Ext.Panel, {
initComponent: function() {
Ext.apply(this, {
layout: 'fit'
,items: [{
xtype : 'dataview'
,store: 'TestStore'
,listeners: {
scope: this
,'render' : function(el) {
el.store.load();
}
}
,tpl: new Ext.XTemplate(
'<tpl for=".">',
'{[this.addPoints(values)]}',
'{points}<br />',
'</tpl>',
'{[this.getTotal()]}',
{
totalPoints: 0
,addPoints : function(values) {
console.log(values.points);
this.totalPoints = this.totalPoints + values.points;
}
,getTotal: function() {
return this.totalPoints;
}
}
)
,autoHeight: true
,multiSelect: false
,itemSelector: 'tr'
}]
});
app.views.testView.superclass.initComponent.apply(this, arguments);
}
});

view1 = new app.views.testView();
app.views.viewport.setActiveItem(view1);
view2 = new app.views.testView();
app.views.viewport.setActiveItem(view2);



stcCallback1004([{"points":5},{"points":10},{"points":12}])

mitchellsimoens
30 Dec 2011, 11:02 AM
is totalPoints ever reset to zero?

EducatedFool
30 Dec 2011, 1:52 PM
Why should I reset the totalPoint? I'm creating a new instance? Or not?



...
{
totalPoints: 0
,addPoints : function(values) {
console.log(values.points);
this.totalPoints = this.totalPoints + values.points;
}
....


view1 = new app.views.testView();
view2 = new app.views.testView();