When using ExtJS to develop an application system, it is inevitable that a JS file contains hundreds of lines or even thousands of lines of code, such as the main program interface or a more complex interface, the following describes how to reduce the number of individual ExtJS JavaScript code lines through custom components.
The main interface in the following figure shows two statistics:
The first time the graph of the JS code is written dead in the Tagpanel, through the ExtJS custom component of the method to split into separate class files after the code:
Ext.define (' App.view.main.Main_Pie_Chart ', {extend: ' Ext.panel.Panel ', alias: ' Widget.main_pie_chart ', Chart_store:
NULL, layout: {type: ' fit '}, Initcomponent:function () {var me = this;
Ext.applyif (Me, {title: ' Inventory Cost distribution pie ', items:[{xtype: ' chart ',//region: ' Center ', Animate:true,
width:450, height:400, Store:me.chart_store, Shadow:true, legend: {position: ' Right ' }, Insetpadding:60, theme: ' Base:gradients ', series: [{type: ' Pie ', field: ' Data1 ', s Howinlegend:true, donut:35, tips: {trackmouse:true, width:140, height:28, re
Nderer:function (Storeitem, item) {//var total = 0;
Storeitem.each (function (REC) {//Total + = Rec.get (' data1 ');
//});
This.settitle (Storeitem.get (' product_name ') + ': ' + math.round (storeitem.get (' data1 ')/total * 100) + '% '); This.settitle (Storeitem. Get (' product_name ') + ': ' +storeitem.get (' data1 ') + ' meta-inventory cost '); }, Highlight: {segment: {margin:20}}, Label: {field: ' Product
_name ', display: ' Rotate ', contrast:true, font: ' 18px Arial '}}]};
Me.callparent (arguments); }
});
The above code defines a class called "App.view.main.Main_Pie_Chart", which needs to be imported with requires in TabPanel, see the following code:
Ext.define (' App.view.Viewport ', {
renderTo:Ext.getBody (),
extend: ' Ext.container.Viewport ',
alias: ' Widget.main_viewport ',
requires: [
' Ext.tab.Panel ',
' Ext.layout.container.Border ',
' App.store.StockChartPieStore ',
' app.view.main.Main_Top_Panel ', '
app.view.main.Main_Pie_Chart ',
' App.view.main.Main_Column_Chart '
],
layout: {
type: ' Border '
},
The code used specifically in the TabPanel of the main interface can be simplified to:
{
xtype: ' TabPanel ',
region: "Center",
ID: ' Content_tabpanel ',
margins: ' 2 5 5 0 ',
activetab:0,
false,
items: [{
id: ' Start-panel ',
title: ' Welcome to use ',
layout: ' Hbox ',
bodystyle: ' padding:25px; Background-image:url (./img/bg.jpg); Background-repeat:no-repeat; background-attachment:fixed; background-position:100% 100% ',
items: [
{
xtype: ' Main_pie_chart ',
chart_store:chart_data_ Store
}
,
{
xtype: ' Main_column_chart ',
chart_store:chart_data_store
}
]
}
Note that this is actually a reference to the two custom ExtJS statistical diagram component classes, two maps corresponding to the same store, so after writing xtype to reference the custom component and then provide Chart_store this ExtJS custom class properties.