1Ext.define (' Testviewmodel ', {2Extend: ' Ext.app.ViewModel ',3 4Alias: ' Viewmodel.test ',//connects to Viewmodel/type below5Constructorfunction(config) {6 //Here you can see the model that was instantiated several times7 console.log (config);8 This. callparent (config);9 },Ten One data: { AFirstName: ' John ', -LastName: ' Doe ' - }, the - formulas: { - //We ' ll explain formulas in more detail soon. -Namefunction(get) { + varfn = Get (' firstName '), ln = get (' LastName '); - return(FN && LN)? (fn + ' + ln): (fn | | ln | | ‘‘); + } A } at }); - -Ext.define (' TestView ', { -Extend: ' Ext.panel.Panel ', -Layout: ' Form ', - in requires: [ -' Testviewmodel ' to ], + - //Always use the this form when defining a view class. this the //allows the creator of the component to pass data without * //erasing the ViewModel type that we want. $ ViewModel: {Panax NotoginsengType: ' Test '//references alias "Viewmodel.test" - }, the + bind: { ATitle: ' Hello {name} ' the }, + -DefaultType: ' TextField ', $ items: [{ $Fieldlabel: ' First Name ', -Bind: ' {firstName} ' - },{ theFieldlabel: ' Last Name ', - bind:{WuyiValue: ' {lastName} ' the } - },{ WuXtype: ' button ', -Text: ' Submit ', About bind: { $Hidden: ' {!name} ' - } - },{ -Xtype: ' Demo ' A }] + }); the -Ext.onready (function () { $Ext.create (' TestView ', { the renderTo:Ext.getBody (), thewidth:400 the }); the }); - in theExt.define (' Demo ', { theExtend: ' Ext.panel.Panel ', AboutLayout: ' Form ', theAlias: ' Widget.demo ', the the requires: [ +' Testviewmodel ' - ], the //Always use the this form when defining a view class. thisBayi //allows the creator of the component to pass data without the //erasing the ViewModel type that we want. theInitComponent:function(){ - //THIS.OWNERCT - //var parent = this.findparentbytype (' panel '); the //Console.log (parent.title); the the varf = This. Getviewmodel (). Get (' FirstName '); the Console.log (f); - This. Callparent (arguments); the }, the //This place is empty, you can use the same model as the main container, if you viewmodel:{type:test}, it is equivalent to the //Instantiate an example of a model94 ViewModel: { the the }, the 98 bind: { AboutTitle: ' {firstName} ' - }101 102});
/*
When there are several components in a container common to one controller and one model
When using a controller in a component: ' Main ', a container component can be used to share one, when the container is instantiated, that is, a director
However, when you use Viewmodel:type: ' main ' in your component, you need to consider it because each component instantiates a
Model, if you want the container and the component to share a model, an instantiation. Set Viewmodel:{type: ' Main '} in the container, set ViewModel in the component: {}, empty it.
*/
EXTJS5 a container has several components that are common to one controller and one model