In the previous article, we spoke about the elements of the Avalon array, which is an array listener for Avalon.
Avalon has a method of monitoring changes, namely $watch. This method can listen for changes in the Avalon attribute, and will trigger the defined method when the change is heard. There is a problem with the Avalon array being listened to: only the changes of the array length can be monitored, and the modification of the array elements cannot be monitored. The following example:
VarVM =Avalon.Define ({
$id:' Test ',
Arr:[]
});
SetTimeout (function () {
Vm.arr = [1,2,3,4,5];
},1000);
SetTimeout (function () {
Avalon.Array.Ensure (Vm.Arr6)
},2000);
settimeout (function () {
Span style= "color: #660e7a; Font-weight:bold; Font-style:italic ">avalon. array. remove (vm.< Span style= "color: #660e7a; Font-weight:bold ">arr,6"
},3000);
vm. $watch (function () {
console.< Span style= "COLOR: #7a7a43" >log ( "array changed ')
})
The console will output three times: The array is changed, the creation of the array, the addition and deletion of elements will be monitored, and then look at another situation:
VarVM =Avalon.Define ({
$id:' Test ',
Arr:[]
});
SetTimeout (function () {
Vm.arr = [1,2,3,4,5];
},1000);
settimeout (function () {
vm.arr[0]=0;
}, 2000);
vm. $watch (function () {
console.< Span style= "COLOR: #7a7a43" >log ( "array changed ')
})
ARR has successfully modified the element labeled 0, but the console outputs only once: the array has changed, indicating that Avalon's $watch can only listen for changes in the array length, and cannot listen for changes to the individual elements of the array.
Later through further study found there is still a way to monitor the array elements of Avalon, but I'm sleepy, tomorrow ^_^
Avalon Array Characteristics (ii)