[ExtJS5 Study Notes] section 16th use the ViewModel attribute added by panel to bind data to Extjs5
In versions earlier than Sencha ext js 5, the concept of viewmodel was not used. Now that extjs5 supports the mvvm mode, her components also add default support for mvvm. Now let's take a look at the frequently-used panel component's powerful support for the mvvm mode.
First, let's take a look at the document's definition of the panel's viewmodel attribute:
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}Translate the above information as follows:
ViewModel: the attribute can be set as a String, an Object, or Ext. app. ViewModel.
ViewModel is the data provider of this component and sub-component. A typical usage of the data contained in ViewModel is to add the bind configuration to the component for rendering or editing data.
After the settings are complete, viewmodel creates and connects to any parent component at the inheritance level. Once created, the parent component cannot be changed.
If the root viewmodel is used, datamodel is associated with the data node, which is determined by obtaining the inherited node.
Default: {$ value: null, lazy: true}
To put it simply, when you want to obtain data from other models in panle, you need to create a viewmodel. This allows you to obtain data from viewmodel.