[ExtJS5學習筆記]第十六節 Extjs5使用panel新增的ViewModel屬性綁定資料
Sencha ext js 5之前的版本中是沒有viewmodel這個概念的,現在extjs5既然支援mvvm模式了,那麼她的組件也就相應的增加了對mvvm的預設支援。現在看看我們經常使用的panel組件對mvvm模式的強大支援。
先看看文檔對panel的viewmodel屬性的定義:
viewModel : String/Object/Ext.app.ViewModelThe ViewModel is a data provider for this component and its children. The data contained in the ViewModel is typically used by adding bind configs to the components that want present or edit this data.When set, the ViewModel is created and links to any inherited viewModel instance from an ancestor container as the parent. The ViewModel hierarchy, once established, only supports creation or destruction of children. The parent of a ViewModel cannot be changed on the fly.If this is a root-level ViewModel, the data model connection is made to this component's associated Data Session. This is determined by calling getInheritedSession.Defaults to: {$value: null, lazy: true}將上述資訊翻譯一下如下:
viewModel:屬性可以設定為字串String或者Object對象或者是Ext.app.ViewModel
ViewModel是這個組件和子構件的資料提供者,ViewModel中包含的資料典型的使用方法就是增加bind配置到想呈現或者編輯資料的組件上。
當設定好了,viewmodel就建立並串連到繼承層次上任何父組件,一旦建立,父組件就無法更改子構件。
如果是根viewmodel,datamodel就關聯到資料節點,這有擷取繼承節點來決定。
預設:{$value:null, lazy:true}
簡單說,就是當你想在panle中擷取其他model的data中的資料的時候,就需要制定viewmodel,這有就可以從viewmodel中擷取資料啦。