The this pointer is typically a variable that exists based on the hosting environment, typically pointing to the host object, whereas for the MVVM framework, you need to create an operation on your own object in the VM, and you can use the method defined in the VM in V (view), which helps to understand:
JS model var vm = Avalon.define ({$id: ' VmID ', $getData: function () {console.log (this);//The point of the pointer is not determined by the location of the call) a Valon.ready (function () {VM. $getData ();}) DOM structure <div ms-controller= "VmID" > <a href= "javascript:void (0);" ms-click= "$getData ()" > Get Data </a> </div>
In this way, the VM object is used to print the method in the VM model, and the DOM node object is printed for the model object method call used in the DOM node, so be careful when using the this pointer in the MVVM framework.
The solution could be to redefine a method instead of directly using the $getdata () method in the VM object:
JS model var vm = Avalon.define ({$id: ' VmID ', $getData: function () {console.log (this); The pointer is indeterminate}, $jump: function () {console.log (this); The this pointer points to the DOM node object vm. $getData (); VM pointer to model object}}) Avalon.ready (function () {VM. $getData ();}) DOM structure <div ms-controller= "VmID" > <a href= "javascript:void (0);" ms-click= "$jump ()" > Get Data </a></ Div>
Precautions for use of this in AVALONJS