您可以擴展配置
var config = {
// do you shared config here
}
// and apply any different/extending configs here
var config1 = Ext.apply(config, { title: "Title of config 1" }
var config2 = Ext.apply(config, { title: "Title of config 2" }
var chart1 = new Ext.chart.LineChart(config1);
var chart2 = new Ext.chart.LineChart(config2);
如果你想讓它更短:
var chart1 = new Ext.chart.LineChart(Ext.apply(config, {
title: "Title of config 1"
});
var chart2 = new Ext.chart.LineChart(Ext.apply(config, {
title: "Title of config 2"
});
編輯:隨着Ext.extend:
Ext.chart.LineChart = Ext.extend(Ext.chart.LineChart, {
// put your shared config in here
});
var chart1 = new Ext.chart.LineChart({
title: "Title of chart 1",
store: new Ext.data.Store({ ... });
});
var chart2 = new Ext.chart.LineChart({
title: "Title of chart 2",
store: new Ext.data.Store({ ... });
});
謝謝,這是一個斯文。我也想知道這是否可以通過擴展機制來實現? – hguser 2010-10-10 13:26:37
是的,你可以。您已經可以將所有默認配置都放入LineChart中,然後只覆蓋已更改的配置 – Tseng 2010-10-10 13:46:45