Mini MVVM Framework AVALONJS Tutorial 6, insert removal processing

Source: Internet
Author: User

Ms-if is one of the process bindings that, if the expression is true, prints the current element out of the page, rather than moving it out of the DOM tree. Its effect looks similar to the ms-visible effect in the previous section, but it affects: empty pseudo-class, and can be more economical performance. MS-IF also has a branch, called Ms-if-loop, which is used in conjunction with the ms-repeat binding, so say it later.

We can compare the two with the following example:

<! DOCTYPE html>

The implementation of MS-IF is much more complex than ms-visible, and if it is initially scanned to this element and evaluates to FALSE, it will no longer scan the elements inside, and immediately remove this element. This is the key to better performance than ms-visible. To be able to find the correct location when re-inserting the DOM, Avalon has to create a note node to do the signpost. The removed element is placed in a div called ifsanctuary, which facilitates unified management.

"If": function (data, vmodels) {//This is the first time the execution of a scan is var elem = data.element Elem.removeattribute (data.name) if (!data . placehoder) {data.msindocument = Data.placehoder = Doc.createcomment ("Ms-if")} data.vmodels = Vmodels p  Arseexprproxy (Data.value, Vmodels, data)}, "If": Function (val, elem, data) {//This is the execution var viewmodel each time the Placehoder corresponding property is changed) Data.placehoder if (val) {//Insert back DOM tree if (!data.msindocument) {data.msindocument = True if        (Placehoder.parentnode) Placehoder.parentNode.replaceChild (Elem, Placehoder)}}        if (Rbind.test (Elem.outerHTML.replace (RLT, "<"). Replace (RGT, ">"))) {scanattr (Elem, Data.vmodels) }} else {//move out of the DOM tree, put into the ifsanctuary Div, and occupy the original position with the annotation node if (data.msindocument) {data.msindocument = Fals E if (elem.parentnode) elem.parentNode.replaceChild (Placehoder, elem)} pl    Acehoder.elem = Elem        Ifsanctuary.appendchild (Elem)}}, 

Finally, let's end this chapter with a switch-card example.

<! DOCTYPE html>

Mini MVVM Framework AVALONJS Tutorial 6, insert removal processing

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.