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 负值方法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>
- 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" >  <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!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
