PDA

View Full Version : Why when adding to container is only the last item added?



xjscrafter
21 Mar 2014, 2:48 PM
In the following code, only the last item is added to col1 and col2.


initializeCharts: function() {
var a = 0, col1Content = [], col2Content = [];
// initialize the default charts from constant config data
var col1 = this.getPerformanceOverviewpoolPanel().queryById('col1');
var col2 = this.getPerformanceOverviewpoolPanel().queryById('col2');
for(a = 0;a < DefaultMetrics.DEFAULT_METRICS.length;a++) {
var chart = Ext.create('com.atlas.view.portlet.GraphiteChartPortlet', DefaultMetrics.DEFAULT_METRICS[a]);
chart.title = DefaultMetrics.DEFAULT_METRICS[a].chartTitle;
if(a % 2) {
col2Content.push(chart);
} else {
col1Content.push(chart);
}
}
col1.add(col1Content);
col2.add(col2Content);
},

xjscrafter
21 Mar 2014, 3:07 PM
Can anyone help on this?

evant
21 Mar 2014, 3:40 PM
The description is too vague. Put together a fiddle: http://fiddle.sencha.com

xjscrafter
21 Mar 2014, 3:44 PM
What is vague? The add() method is not working. When might it fail like this, adding only the last item?

evant
21 Mar 2014, 3:46 PM
It's vague because it's not in any context. What is col1 and col2? How are they contained? What is the class you're creating, how is it defined? How many times are you looping? Maybe your loop counter is wrong.

There's so many things it could possibly be. Put together a fiddle.

xjscrafter
24 Mar 2014, 7:51 AM
I see. I guess I thought the add() method should just add something to a container.

I'm using the Ext.app.Portlet feature.

I'm trying to add portlets dynamically.


initializeCharts: function() {
var a = 0, col1Content = [], col2Content = [];
// initialize the default charts from constant config data
var col1 = this.getPerformanceOverviewpoolPanel().queryById('col1');
var col2 = this.getPerformanceOverviewpoolPanel().queryById('col2');
for(a = 0;a < DefaultMetrics.DEFAULT_METRICS.length;a++) {
var chart = Ext.create('com.atlas.view.portlet.GraphiteChartPortlet', DefaultMetrics.DEFAULT_METRICS[a]);
chart.title = DefaultMetrics.DEFAULT_METRICS[a].chartTitle;
if(a % 2) {
col2Content.push(chart);
} else {
col1Content.push(chart);
}
}
col1.add(col1Content);
col2.add(col2Content);
},

But after this only the last portlet is added for each column.

evant
24 Mar 2014, 1:18 PM
As I said above, there's not enough information. Posting the same code doesn't provide that. You'll need to put together a fiddle. The upside is that during putting together the fiddle, you'll probably figure out your problem anyway.