Avalon Array Feature (i)

Source: Internet
Author: User

Avalon is an MVVM framework developed by the great Gods of the country, which is lighter than angular. For project reasons, Avalon was my first frame of contact in addition to jquery, with a deep natural feeling. But I also stepped on a lot of Avalon's pits, as a record, don't step on it.

First of all, I want to talk about some of the pits I trod in the Avalon array.

In general, when we add new elements to an array, we use the push method, but this method is not valid for Avalon, see the following code:

VarVM =Avalon.Define ({
$id:' Test ',
Arr:[]
});
SetTimeout (function () {
Vm.arr = [1,2,3,4,5];
Console.log (vm.arr)
},1000);
settimeout (function () {
vm.arr.push = 6;
console. log (vm.arr[5])
},2000)

Output undefined after 2 seconds, proving that Avalon adds an array cannot use the push method. Viewing the official documentation, you can see that Avalon has its own array method, where new elements are added by Avalon. Array. ensure

VarVM =Avalon.Define ({
$id:' Test ',
Arr:[]
});
SetTimeout (function () {
Vm.arr = [1,2,3,4,5];
Console.LogVm.arr)
},1000);
settimeout (function () {
avalon.array. ensure (vm.< Span style= "color: #660e7a; Font-weight:bold ">arr,6);
console. Log (vm.arr[5])
},2000)

Output 6, the explanation is feasible.

Avalon Array Feature (i)

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.