extjs自訂群組件類

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

在使用extjs開發應用系統時,難免會出現一個js檔案內包含數百行甚至上千行代碼的情況,例如程式主介面或者複雜一點的介面,下面介紹如何通過自訂群組件減少單個extjs javascript程式碼數的方法。

中的主介面顯示了兩個統計圖:



最初的時候統計圖的js代碼是寫死在tagpanel裡面的,通過extjs 自訂群組件的方法拆分成單獨的類檔案以後的代碼:


 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:'庫存商品成本分布餅圖',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',showInLegend: true,donut: 35,tips: {trackMouse: true,width: 140,height: 28,renderer: 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')+'元庫存成本');}},highlight: {segment: {margin: 20}},label: {field: 'product_name',display: 'rotate',contrast: true,font: '18px Arial'}}]}]});me.callParent(arguments);}});

上面的代碼中定義了一個叫做“app.view.main.Main_Pie_Chart”的類,在tabpanel裡面需要引用時需要藉助requires匯入,見下面的代碼:


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‘    },


具體在主介面的tabpanel使用的代碼就可以簡化為:


 {    xtype: ‘tabpanel‘,    region: "center",    id: ‘content_tabpanel‘,    margins: ‘2 5 5 0‘,    activeTab: 0,    border: false,    items: [{        id: ‘start-panel‘,        title: ‘歡迎使用‘,        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            }        ]    }

注意這裡面其實是引用了兩個自訂的extjs 統計圖組件類,兩個圖對應同一個store,所以在寫完xtype去引用自訂群組件後又提供了chart_store這個extjs自訂類屬性。



extjs自訂群組件類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.