本文地址:[http://blog.csdn.net/sushengmiyan/article/details/39078627](http://blog.csdn.net/sushengmiyan/article/details/39078627)
sencha官方API:[?http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.panel.Panel-cfg-viewModel](http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.panel.Panel-cfg-viewModel)[](http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext-method-each)
本文作者:[sushengmiyan](http://blog.csdn.net/sushengmiyan)
------------------------------------------------------------------------------------------------------------------------------------
?Sencha ext js 5之前的版本中是沒有viewmodel這個概念的,現在extjs5既然支持mvvm模式了,那么她的組件也就相應的增加了對mvvm的默認支持。現在看看我們經常使用的panel組件對mvvm模式的強大支持。
先看看文檔對panel的viewmodel屬性的定義:
~~~
viewModel : String/Object/Ext.app.ViewModel
The 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中獲取數據啦。
- 前言
- [EXtJS5學習筆記]第一節 Sencha Cmd 學習筆記 簡介 Sencha Cmd是什么
- [ExtJS5學習筆記]第二節 Sencha Cmd 學習筆記 使你的sencha cmd跑起來
- [ExtJS5學習筆記]第三節 sencha cmd學習筆記 生成應用程序構建的內部細節
- [ExtJS5學習筆記]第四節 歡迎來到extjs5-手把手教你實現你的第一個應用
- [ExtJS5學習筆記]第五節 使用fontawesome給你的extjs5應用增加字體圖標
- [ExtJS5學習筆記]第六節 Extjs的類系統Class System命名規則及定義和調試
- [ExtJS5學習筆記]第七節 Extjs5的組件components及其模板事件方法學習
- [ExtJS5學習筆記]第八節 Extjs5的Ext.toolbar.Toolbar工具條組件及其應用
- [ExtJS5學習筆記]第九節 Extjs5的mvc與mvvm框架結構簡介
- [ExtJS5學習筆記]第十節 Extjs5新增特性之ViewModel和DataBinding
- [ExtJS5學習筆記]第十一節 Extjs5MVVM模式下系統登錄實例
- [ExtJS5學習筆記]第十二節 Extjs5開發遇到的問題列表記錄
- [ExtJS5學習筆記]第十三節 Extjs5的Ext.each方法學習
- [ExtJS5學習筆記]第十四節 Extjs5中data數據源store和datapanel學習
- [ExtJS5學習筆記]第十五節 Extjs5表格顯示不友好?panel的frame屬性在作怪
- [ExtJS5學習筆記]第十六節 Extjs5使用panel新增的ViewModel屬性綁定數據
- [ExtJS5學習筆記]第十七節 Extjs5的panel組件增加accodion成為折疊導航欄
- [ExtJS5學習筆記]第十八節 Extjs5的panel的dockeditems屬性配置toolbar
- [ExtJS5學習筆記]第十九節 Extjs5中通過設置form.Panel的FieldSet集合屬性控制多個field集合
- [ExtJS5學習筆記]第二十節 Extjs5配合數組的push方法,動態創建并加載組件
- [ExtJS5學習筆記]第二十一節 Extjs5中使用config配置給ext.widget或者create方法傳遞參數
- [ExtJS5學習筆記]第二十二節 Extjs5中使用beforeLabelTpl配置給標簽增加必填選項星號標志
- [ExtJS5學習筆記]第二十三節 Extjs5中表格gridpanel的列格式設置
- [ExtJS5學習筆記]第二十四節 Extjs5中表格gridpanel或者表單數據后臺傳輸remoteFilter設置
- [ExtJS5學習筆記]第二十五節 利用window.open()函數實現ExtJS5的登陸頁面跳轉
- [EXTJS5學習筆記]第二十六節 在eclipse/myeclipse中使用sencha extjs的插件
- [ExtJS5學習筆記]第二十七節 CMD打包錯誤 Error C2009: YUI Parse Error (identifier is a reserved word => debugger;)
- [ExtJS5學習筆記]第二十八節 sencha ext js 5.1.0發布版本正式發布 extjs doc下載地址
- [ExtJS5學習筆記]第二十九節 sencha ext js 5.1.0中動態更換皮膚主題
- [ExtJS5學習筆記]第三十節 sencha extjs 5表格gridpanel分組匯總
- [ExtJS5學習筆記]第三十一節 sencha extjs 5使用cmd生成的工程部署到tomcat服務器
- [ExtJS5學習筆記]第三十二節 sencha extjs 5與struts2的ajax交互配置
- [ExtJS5學習筆記]第三十五節 sencha extjs 5 組件查詢方法總結