Avalon Array Characteristics (ii)

Source: Internet
Author: User
Tags array length

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.