search
HomeWeb Front-endJS TutorialIntroduction to epii.js template engine
Introduction to epii.js template engineJul 18, 2017 pm 04:58 PM
javascript

What is epii.js

  • epii.js is a template engine that can quickly bind data to UI, quickly bind events, and Processing, does not rely on any third-party libraries, only 8k, can be used in native+webapp development, web development, h5 micro web pages, and does not conflict with other frameworks.

  • Let developers focus more on the application itself, instead of spending a lot of time implementing data and UI, and event processing. Efficiency is greatly improved.

Project address


1, basic data binding

  • epii The custom dom node attribute r-data can be assigned to any type of node. The input node is assigned its value attribute, the img node is assigned its src attribute, and other types of nodes are assigned the innerHtml attribute.

  • If r-data-default is set, the default value will be displayed when there is no data.

  • The difference between r-data="title" and r-data="{title}" is that when the title value does not exist, the title string will be displayed in the first case. In the second case, it displays empty. If r-data-default is set in the second case, the default value of its setting is displayed

  • The effect of the following code can be previewed here https:// epaii.github.io/epii.js/demo/demo1.html

    <div>
      <h1>
      </h1>
      <div></div>
      <br>
       <div></div>
    <!-- 默认值-->
      <br>
      <input><!-- input 负值方法1-->
      <input><!-- input 负值方法2-->
      <br>
      <img  alt="Introduction to epii.js template engine" ><!-- img 负值方法1-->
      ![]({img_url})<!-- img 负值方法2  ,但这种存在缺点,因为在解析前,已经加载一次不存在的图片,多一次请求,不推荐-->
    </div>
    <script>  var myepii = epii(document.getElementById("content"));//初始化殷勤,需要制定dom节点 可以是 body
      myepii.setData({
          title: "我是标题",
          content: "我是内容主题",
          inputvalue: "input内容",
          img_url:"https://www.baidu.com/img/bd_logo1.png",
          img_width:100
      });
    
      setTimeout(function () {
          myepii.setData({
              title: "我是新的标题",
              content: "我是新的内容主题"  });
      }, 3000);</script>

    2 Other syntax for data binding

  • epii can realize variable binding of dom node attributes, and variable tags can be used in any attributes, such as style, width, and other attributes. The effect of the following code can be previewed here

  • Support chain variables, such as {info.subject}
    https://epaii.github.io/epii.js/demo/demo2.html

##
<div>
    <h1>
    </h1>
    <div></div>
    <br>
    <img  alt="Introduction to epii.js template engine" >

</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        h1_width:100,
        h1_height:100,
        h1_color:"red",
        title: "我是标题",
        info:{subject:"文章简介"},
        img:{
            img_url: "https://www.baidu.com/img/bd_logo1.png",
            img_width: 100}
    });

    setTimeout(function () {
        myepii.setData({
            title: "我是新的标题",
            h1_width:300,
            h1_height:300,
            h1_color:"blue",
            img:{  img_width:300}
        });
    }, 3000);</script>

3 Node hiding/showing

  • epii There are two ways to set the hiding and display of dom nodes

  • Method 1, style="display: {h1_display}" Bind through the style attribute

  • Method 2, through the r-display tag r-display="{img_show}-1== 0", must be a bool equation string, it is recommended to use this method

  • The effect of the following code can be previewed here https://epaii.github.io/epii.js/ demo/demo3.html

<div>
    <h1> <!--第一种方法,直接在style中 用变量,不推荐-->
    </h1>
    <br>
    <img  alt="Introduction to epii.js template engine" ><!--第二种方法,使用 r-display 标签,推荐-->

</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        title: "我是标题",
        h1_display:"block",

        img_url:"https://www.baidu.com/img/bd_logo1.png",
        img_show:1});

    setTimeout(function () {//两种方法隐藏        myepii.setData({
            h1_display:"none",
            img_show:0});
    }, 3000);</script>

4 Click event

    ##epii via r-click -change and r-click-function are two tags that implement click events. Variable symbols can be used in tag content. The r-click-change tag implements click-based custom jumps, and the r-click-function tag implements click-triggered custom functions.
  • r-click-change="http://www.baidu.com/?1={title}" Jump directly when clicked
  • r-click-function="on_subject_click#{info.subject}#{title}" and onclick="on_subject_click('{info.subject}','{title}')" have the same effect. It is recommended to use the former
  • onclick, r-click-change, r-click-function The same node cannot be reused
  • The effect of the following code can be previewed here https://epaii.github.io/epii.js/demo/demo9.html
<div>
    <h1 id="">  </h1>
    
    <div></div>
    <br>
    <div></div>
    <br>
    <div>
        <div>名称<span></span>,
            年龄<span></span>
        </div>
    </div>
</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        title: "列表展示",
        info:{subject:"文章简介"},
        users:[
            {name:"张三",age:"12岁"},
            {name:"李四",age:"14岁"}
        ]
    });function on_subject_click(subject,title) {
        console.log(subject,title);

    }function on_item_click(name,age) {
        console.log(name,age);
    }</script>

5 Custom jump event

    Use epii.setClickToChangeFunction(f); to customize the r-click-change event. In native+webapp development, it is generally not necessary to jump directly through the location page, but needs to be processed. Custom protocol.
epii.setClickToChangeFunction(function (url) {
        console.log(url);
    });

    The effect of the following code can be previewed here https://epaii.github.io/epii .js/demo/demo10.html
 //自定义r-click-change 处理事件, 在native+webapp开发中 一般需要自定义协议epii.setClickToChangeFunction(function (url) {
        console.log(url);
    });var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        title: "列表展示",

    });

6 List (Basic)

    epii Specify this dom node through the r-list tag to display the list. The variables in the list node will automatically switch to a certain item of data in the list. All tags before the list. The effect of the following code can be previewed here https://epaii .github.io/epii.js/demo/demo4.html
<div>
    <h1 id="">  </h1>
    <div>
        <div>名称<span></span>,年龄<span></span>
</div>
    </div>
</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        title: "列表展示",
        users:[
            {name:"张三",age:"12岁"},
            {name:"李四",age:"14岁"}
        ]
    });</script>

7 List (multiple templates)

    If there are multiple templates in the list, the corresponding template will be automatically selected according to r-display. The effect of the following code can be previewed here https://epaii.github.io/epii.js/demo /demo5.html
<div>
    <h1 id="">  </h1>
    <div>
        <div>,年龄<span></span>
</div>
        <div>,年龄<span></span>
</div>
    </div>
</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        title: "列表展示",
        users:[
            {name:"张三",age:"12岁",item_type:1},
            {name:"李四",age:"14岁",item_type:2},
            {name:"张三1",age:"121岁",item_type:1},
            {name:"李四1",age:"141岁",item_type:2}
        ]
    });</script>

8 List (append data)

    epii can be two There are two ways to append data to the list
  • Method 1, re-setData, will re-display all the data in the list, if the old data has changed, use this method
  • Method 2, addData, existing data remains unchanged, append data, if there is no change in the old data, it is recommended to use this method
  • The effect of the following code can be previewed here https://epaii.github.io/epii.js/demo/demo6.html
<div>
    <h1 id="">  </h1>
    <div>
        <div>,年龄<span></span>
</div>
        <div>,年龄<span></span>
</div>
    </div>
</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 body    myepii.setData({
        title: "列表展示",
        users:[
            {name:"张三",age:"12岁",item_type:1},
            {name:"李四",age:"14岁",item_type:2},
            {name:"张三1",age:"121岁",item_type:1},
            {name:"李四1",age:"141岁",item_type:2}
        ]
    });
    setTimeout(function () {//3秒后追加列表myepii.addData({ //追加已有数据,列表将被追加,其它类型直接覆盖title: "追加列表展示",
            users:[
                {name:"张三5",age:"12岁",item_type:1},
                {name:"李四6",age:"14岁",item_type:2},
                {name:"张三7",age:"121岁",item_type:1},
                {name:"李四8",age:"141岁",item_type:2}
            ]
        });

    },3000);</script>

 

9 列表(空数据)

通过 r-empty="1" 设置当数据为空,或者未设置时候列表的样式,以下代码效果可在此处预览 https://epaii.github.io/epii.js/demo/demo7.html

<div>
    <h1 id="">  </h1>
    <div>
        <div>,年龄<span></span>
</div>
        <div>,年龄<span></span>
</div>
        <div>
    </div>
</div>
<script>
    var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 body
    myepii.setData({
        title: "列表展示",
        users:[]
    });
    setTimeout(function () {//3秒后追加列表
        myepii.addData({ //追加已有数据,列表将别被加,其它类型直接覆盖
            title: "追加列表展示",
            users:[
                {name:"张三5",age:"12岁",item_type:1},
                {name:"李四6",age:"14岁",item_type:2},
                {name:"张三7",age:"121岁",item_type:1},
                {name:"李四8",age:"141岁",item_type:2}
            ]
        });

    },3000);

</script>
</div><p> </p><h1 id="数据获取-获取已设置的数据-getData-getDataValue两个方法">10 数据获取,获取已设置的数据,getData,getDataValue两个方法</h1>
  • 通过 epii 的 getData 方法 可以获取所有设置的数据

  • 通过 epii的 getDataValue 方法 可以快速获取已设置的数据,getDataValue 支持多参数,链条key

  • 如 myepii.getDataValue("title"); myepii.getDataValue("info","subject"); myepii.getDataValue("users",1,"age")

  • 以下代码效果可在此处预览 https://epaii.github.io/epii.js/demo/demo8.html

<div>
    <h1 id="">  </h1>
    <div>
        <div>,年龄<span></span>
</div>
        <div>,年龄<span></span>
</div>
    </div>
</div>
<script>var myepii = epii(document.getElementById("content"));//初始化引擎,需要制定dom节点 可以是 bodymyepii.setData({
        title: "获取数据",
        info:{subject:"标题"},
        users:[
            {name:"张三",age:"12岁",item_type:1},
            {name:"李四",age:"14岁",item_type:2},
            {name:"张三1",age:"121岁",item_type:1},
            {name:"李四1",age:"141岁",item_type:2}
        ]
    });
    console.log(myepii.getData());
    alert(myepii.getDataValue("title"));
    alert(myepii.getDataValue("info","subject"));
    alert(myepii.getDataValue("users",1,"age"));</script>

 

11 完整的demo,几乎涉及所有语法

demo案例源码:()

demo案例效果:(https://epaii.github.io/epii.js/index.html)

<div>
    <div>

    </div>
    <div>click_to_change</div>
    <div>

    </div>
    <div>{bgcolor};display: {display}" >

    </div>
    <div>

    </div>
    <img  alt="Introduction to epii.js template engine" >
    ![]({img_url})
    <input>
    <input>
    <div>

        <span></span>
        <span></span>
        <div>
            <div> 二级列表:</div>
            <div>
                <span></span>
                <span>
                    </span>
            </div>


        </div>
        <span>真的没有数据</span>

    </div>
</div>
<script>epii.setClickToChangeFunction(function (url) {
        alert(url);
    });function index(c, b) {//this  bind to uiviewconsole.log(this.innerHTML);
        console.log(c);
        console.log(b);
    }var data = {"img_url":"https://www.baidu.com/img/bd_logo1.png","display":"block","width":100,"height":200,"bgcolor":"red","name": "张三","sex": "男","isshow": 1,"show_name": "show/hide","map":{"show":"1","age":"map_age"},         "list": [{"name": "list_item_1", "moban": 1}, {"name": "list_item_2", "moban": 2, "age": 2}]
    };var myepii = epii(document.body);

    myepii.setData(data);//模拟数据变化setTimeout(function () {
        myepii.setData({//改变已有数据"hebei":"河北邯郸","name": "李四","sex": "女","map":{"show":"0","age":"map_age1"},"bgcolor":"blue","width":500,"height":50,
            isshow: 0});
        setTimeout(function () {
            myepii.addData({//追加已有数据,列表将被追加,其它类型直接覆盖"hebei":"河北石家庄",                 "display":"none","list": [
                    {"name": "list_item_3", "moban": 1},
                    {"name": "list_item_4", "moban": 2, "age": 4},
                    {"moban": 3,"age": 10,"wanju": [{"name": "list_item_list1", "moban": 1}, {"name": "list_item_list2", "moban": 2, a: 5}]
                    }]
            });
            console.log(myepii.getDataValue("name"));
            console.log(myepii.getDataValue("list",1,"age"));
            console.log(myepii.getDataValue("list",4,"wanju",1,"name"));
        },3000);




    }, 3000);</script>

 

The above is the detailed content of Introduction to epii.js template engine. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
es6数组怎么去掉重复并且重新排序es6数组怎么去掉重复并且重新排序May 05, 2022 pm 07:08 PM

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

JavaScript的Symbol类型、隐藏属性及全局注册表详解JavaScript的Symbol类型、隐藏属性及全局注册表详解Jun 02, 2022 am 11:50 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

原来利用纯CSS也能实现文字轮播与图片轮播!原来利用纯CSS也能实现文字轮播与图片轮播!Jun 10, 2022 pm 01:00 PM

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

JavaScript对象的构造函数和new操作符(实例详解)JavaScript对象的构造函数和new操作符(实例详解)May 10, 2022 pm 06:16 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

javascript怎么移除元素点击事件javascript怎么移除元素点击事件Apr 11, 2022 pm 04:51 PM

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

JavaScript面向对象详细解析之属性描述符JavaScript面向对象详细解析之属性描述符May 27, 2022 pm 05:29 PM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

foreach是es6里的吗foreach是es6里的吗May 05, 2022 pm 05:59 PM

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。

整理总结JavaScript常见的BOM操作整理总结JavaScript常见的BOM操作Jun 01, 2022 am 11:43 AM

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)