extjs5 一個容器中有幾個組件公用一個控制器和一個模型

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   使用   sp   for   on   

  1 Ext.define(‘TestViewModel‘, {  2   extend: ‘Ext.app.ViewModel‘,  3   4   alias: ‘viewmodel.test‘, // connects to viewModel/type below  5   constructor: function(config){  6     //這裡可以看出執行個體化了幾次的 model  7     console.log(config);  8     this.callParent(config);  9   }, 10  11   data: { 12     firstName: ‘John‘, 13     lastName: ‘Doe‘ 14   }, 15  16   formulas: { 17     // We‘ll explain formulas in more detail soon. 18     name: function (get) { 19       var fn = get(‘firstName‘), ln = get(‘lastName‘); 20       return (fn && ln) ? (fn + ‘ ‘ + ln) : (fn || ln || ‘‘); 21     } 22   } 23 }); 24  25 Ext.define(‘TestView‘, { 26   extend: ‘Ext.panel.Panel‘, 27   layout: ‘form‘, 28  29   requires: [ 30     ‘TestViewModel‘ 31   ], 32  33   // Always use this form when defining a view class. This 34   // allows the creator of the component to pass data without 35   // erasing the ViewModel type that we want. 36   viewModel: { 37     type: ‘test‘  // references alias "viewmodel.test" 38   }, 39  40   bind: { 41     title: ‘Hello {name}‘ 42   }, 43  44   defaultType: ‘textfield‘, 45   items: [{ 46     fieldLabel: ‘First Name‘, 47     bind: ‘{firstName}‘ 48   },{ 49     fieldLabel: ‘Last Name‘, 50     bind:{ 51       value: ‘{lastName}‘ 52     }  53   },{ 54     xtype: ‘button‘, 55     text: ‘Submit‘, 56     bind: { 57       hidden: ‘{!name}‘ 58     } 59   },{ 60     xtype: ‘demo‘ 61   }] 62 }); 63  64 Ext.onReady(function () { 65   Ext.create(‘TestView‘, { 66     renderTo: Ext.getBody(), 67     width: 400 68   }); 69 }); 70  71  72 Ext.define(‘Demo‘, { 73   extend: ‘Ext.panel.Panel‘, 74   layout: ‘form‘, 75   alias: ‘widget.demo‘, 76  77   requires: [ 78     ‘TestViewModel‘ 79   ], 80   // Always use this form when defining a view class. This 81   // allows the creator of the component to pass data without 82   // erasing the ViewModel type that we want. 83   initComponent: function(){ 84     //this.ownerCt 85     //var parent = this.findParentByType(‘panel‘); 86     //console.log(parent.title); 87  88     var f = this.getViewModel().get(‘firstName‘); 89     console.log(f); 90     this.callParent(arguments); 91   }, 92   //這個地方為空白,就可以和主容器使用相同的一個model,如果你viewModel:{type: test},就相當於又 93   //執行個體化了一個model 94   viewModel: { 95  96   }, 97  98   bind: { 99     title: ‘{firstName}‘100   }101   102 });


/*
當一個容器中有幾個組件公用一個控制器和一個模型
在組件中 使用 controller: ‘main‘時 可以容器組件共用一個,此時執行個體化容器時,也就是一個控制器
但是在 組件中 使用 viewModel:type: ‘main‘ 時,就需要考慮了,因為每個組件都會執行個體化一個
模型,如果想容器和組件共用一個模型,一個執行個體化。就在容器中設定viewModel:{type: ‘main‘},組件中設定 viewModel: {}, 為空白就可以了
*/

extjs5 一個容器中有幾個組件公用一個控制器和一個模型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.