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)