代码拉取完成,页面将自动刷新
同步操作将从 Michael Yang/fasty 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Fasty 是一个简约、超快的 JavaScript 模板引擎, 它使用了非常独特的缓存技术,从而获得接近 JavaScript 极限的运行性能,并且同时支持 NodeJS 和浏览器。
Fasty 的渲染速度,超过很多市面上的 JavaScript 引擎 100 倍以上。
{{ }}
和 逻辑指令 {{~ }}
{{ $("#id").text() }}
示例1
var template = '<div> hello {{ name }} </div>'
var data = {name: "fasty"}
var fasty = new Fasty();
var result = fasty.render(template,data);
// result: <div> hello fasty </div>
示例2
var template = ' {{attr}} hello {{ func1(name) }} ---'
var data = {name: "fasty"}
var fasty = new Fasty({
//共享的模板数据 或者 方法
share : {
attr:'text...',
//定义了模板共享方法,因此在 {{...}} 中可以直接使用
func1: function (v){
return v + " kiss~~"
},
}
});
var result = fasty.render(template,data);
// result: text... hello fasty kiss~~
// #1 变量
{{~ var x = 100}}
{{x}}
//输出: 100
// #2 字符串
{{"hello world"}}
//输出:hello world
// #3 安全输出,对 html 进行 escape
{{* "<div> hello world </div>"}}
//输出:<div> hello world </div>
// #4 强制转换 html 输出
{{! "<div> hello world </div>"}}
//输出:<div> hello world </div>
#1
{{~ var a =100}}
#2
{{~ var a =100,b = 200,c=300}}
#3
#{{~ let a =100}}
#4
#{{~ let a =100,b=200,c=300}}
#4
#{{~ const a =100}}
#5
#{{~ const a =100,b=200,c=300}}
{{~ if (x == 100) }}
{{~ elseif(x == 200) }}
{{~ else if(x == 300) }}
{{~ else }}
{{~ end }}
同时支持 'elseif' or 'else if'
// #1
{{~ for (item of array) }}
{{~end}}
// #2
{{~ for (item in array) }}
{{~end}}
// #3
{{~ for (let item of array) }}
{{~end}}
// #4
{{~ for (const item in array) }}
{{~end}}
// #5
{{~ for (key of Object.keys(item) )}}
{{~end}}
// #6
{{~ for (var x = i;x < 100;x++) }}
{{~ end }}
// #7
{{~ for (item of someMethodInvoke().other()) }}
{{~end}}
// #8
{{~ for (var x = i;x < someMethodInvoke().other();x++) }}
{{~ end }}
#1
{{a?.b?.c}}
#2
{{a.bbbb?().ccc?.ddd}}
var template1 = '{{~for (item of items)}} {{ myRender(item)}} {{~end}}';
var template2 = '{{~for (item of childItems)}} {{ myRender(item)}} {{~end}}';
var fasty = new Fasty({
share : {
//自定义你的递归渲染方法
myRender:function (data){
return fast.render(data,template2)
},
}
});
var data = {
items: [
{
otherAttr: "value1",
childItems: [
{
otherAttr: "value1",
childItems: [],
},
{
otherAttr: "value1",
childItems: [],
},
],
},
{
otherAttr: "value1",
childItems: [
{
otherAttr: "value1",
childItems: [],
},
{
otherAttr: "value1",
childItems: [],
},
],
},
],
};
fast.render(data,template1);
var options = {
//共享模板方法和数据
share : {
attr:'text...',
func1:function (v){
return v + " kiss~~"
},
},
// 是否是共享数据优先
// 默认 false,即: render 方法传入的 data 数据优先
shareDataFirst: false, //default is false
//是否开启安全访问,这个功能不支持 IE 浏览器
//IE 下需要设置为 false,同时配置 false 后会得到更高的运行性能
safelyAccess: true,
//自定义 html 安全输出方法
//当使用 {{# ... }} 的时候使用该方法转换
$escape:function (html){return html},
//自定义 unescape 方法
//当使用 {{! ... }} 的时候使用该方法转换
$unescape:function (value){return value}
}
var fasty = new Fasty(options);
fast.render(template,data)
Fasty is licensed under the MIT License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。